diff --git a/CrossCutting/DataClasses/ConnectionSettings.cs b/CrossCutting/DataClasses/ConnectionSettings.cs index 05cf4dc..bfec987 100644 --- a/CrossCutting/DataClasses/ConnectionSettings.cs +++ b/CrossCutting/DataClasses/ConnectionSettings.cs @@ -8,6 +8,8 @@ namespace CrossCutting.DataClasses { public static class ConnectionSettings { - public const string PipeName = "GimmeAScreenshotPlease.SendScreenshot"; + public const string PrimaryScreenPipeName = "GimmeAScreenshotPlease.SendScreenshotPrimaryScreen"; + public const string ScreenPipeName = "GimmeAScreenshotPlease.SendScreenshotForScreen"; + public const string ScreenListPipeName = "GimmeAScreenshotPlease.SendScreenList"; } } diff --git a/CrossCutting/DataClasses/ScreenInformation.cs b/CrossCutting/DataClasses/ScreenInformation.cs index 75363f7..3c01df9 100644 --- a/CrossCutting/DataClasses/ScreenInformation.cs +++ b/CrossCutting/DataClasses/ScreenInformation.cs @@ -10,5 +10,16 @@ public class ScreenInformation { public int Index { get; set; } public string Name { get; set; } + + public ScreenInformation() + { + + } + + public ScreenInformation(int index, string name) + { + Index = index; + Name = name; + } } } diff --git a/GimmeAScreenshotPlease.sln b/GimmeAScreenshotPlease.sln index cc2190b..8975f77 100644 --- a/GimmeAScreenshotPlease.sln +++ b/GimmeAScreenshotPlease.sln @@ -47,6 +47,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encodings.Contract", "Logic EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Encodings", "Logic\Foundation\Encodings\Encodings.csproj", "{A0865541-5E27-4177-95B4-C2DDC9ABDEA7}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serialization", "Logic\Foundation\Serialization\Serialization.csproj", "{6B38A64D-27B0-4F98-BA53-4204B4394C58}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Serialization.Contract", "Logic\Foundation\Serialization.Contract\Serialization.Contract.csproj", "{E428141B-971F-495E-BF23-277433EB8E32}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -117,6 +121,14 @@ Global {A0865541-5E27-4177-95B4-C2DDC9ABDEA7}.Debug|Any CPU.Build.0 = Debug|Any CPU {A0865541-5E27-4177-95B4-C2DDC9ABDEA7}.Release|Any CPU.ActiveCfg = Release|Any CPU {A0865541-5E27-4177-95B4-C2DDC9ABDEA7}.Release|Any CPU.Build.0 = Release|Any CPU + {6B38A64D-27B0-4F98-BA53-4204B4394C58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6B38A64D-27B0-4F98-BA53-4204B4394C58}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6B38A64D-27B0-4F98-BA53-4204B4394C58}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6B38A64D-27B0-4F98-BA53-4204B4394C58}.Release|Any CPU.Build.0 = Release|Any CPU + {E428141B-971F-495E-BF23-277433EB8E32}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E428141B-971F-495E-BF23-277433EB8E32}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E428141B-971F-495E-BF23-277433EB8E32}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E428141B-971F-495E-BF23-277433EB8E32}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -141,6 +153,8 @@ Global {22FEE8C4-3711-45E8-8085-02754E1EB77F} = {184D9DA9-1150-4646-976E-45E5193AD28A} {4A594EBA-482E-4A2D-8CE0-7AEC059615EA} = {83982FCC-0016-417C-A1C5-39D069B5DAFC} {A0865541-5E27-4177-95B4-C2DDC9ABDEA7} = {83982FCC-0016-417C-A1C5-39D069B5DAFC} + {6B38A64D-27B0-4F98-BA53-4204B4394C58} = {83982FCC-0016-417C-A1C5-39D069B5DAFC} + {E428141B-971F-495E-BF23-277433EB8E32} = {83982FCC-0016-417C-A1C5-39D069B5DAFC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {1B43E731-2B89-4F38-80F7-19D0917FFDAE} diff --git a/Logic/Business/ScreenshotClientWorkflow.Contract/IClientWorkflow.cs b/Logic/Business/ScreenshotClientWorkflow.Contract/IClientWorkflow.cs index 51170b8..b51e718 100644 --- a/Logic/Business/ScreenshotClientWorkflow.Contract/IClientWorkflow.cs +++ b/Logic/Business/ScreenshotClientWorkflow.Contract/IClientWorkflow.cs @@ -1,4 +1,5 @@ -using System; +using CrossCutting.DataClasses; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -9,6 +10,8 @@ namespace Logic.Business.ScreenshotClientWorkflow.Contract { public interface IClientWorkflow { - Bitmap GetScreenshot(string target); + Bitmap GetScreenshotPrimaryScreen(string target); + Bitmap GetScreenshotForScreen(string target, ScreenInformation screenInformation); + IReadOnlyList GetScreenInformationList(string target); } } diff --git a/Logic/Business/ScreenshotClientWorkflow.Contract/ScreenshotClientWorkflow.Contract.csproj b/Logic/Business/ScreenshotClientWorkflow.Contract/ScreenshotClientWorkflow.Contract.csproj index cfe57bb..e919bcb 100644 --- a/Logic/Business/ScreenshotClientWorkflow.Contract/ScreenshotClientWorkflow.Contract.csproj +++ b/Logic/Business/ScreenshotClientWorkflow.Contract/ScreenshotClientWorkflow.Contract.csproj @@ -45,5 +45,11 @@ + + + {22fee8c4-3711-45e8-8085-02754e1eb77f} + DataClasses + + \ No newline at end of file diff --git a/Logic/Business/ScreenshotClientWorkflow/ClientWorkflow.cs b/Logic/Business/ScreenshotClientWorkflow/ClientWorkflow.cs index 508acbc..47c27ce 100644 --- a/Logic/Business/ScreenshotClientWorkflow/ClientWorkflow.cs +++ b/Logic/Business/ScreenshotClientWorkflow/ClientWorkflow.cs @@ -1,4 +1,5 @@ -using Logic.Business.ScreenshotClientWorkflow.Contract; +using CrossCutting.DataClasses; +using Logic.Business.ScreenshotClientWorkflow.Contract; using Logic.Foundation.Client.Contract; using System; using System.Collections.Generic; @@ -18,9 +19,19 @@ public ClientWorkflow(IScreenshotClient client) this.client = client; } - public Bitmap GetScreenshot(string target) + public Bitmap GetScreenshotPrimaryScreen(string target) { - return this.client.GetScreenshot(target, CrossCutting.DataClasses.ConnectionSettings.PipeName); + return this.client.GetScreenshot(target); + } + + public Bitmap GetScreenshotForScreen(string target, ScreenInformation screenInformation) + { + return this.client.GetScreenshot(target, screenInformation); + } + + public IReadOnlyList GetScreenInformationList(string target) + { + return this.client.GetScreenInformationList(target); } } } diff --git a/Logic/Business/ScreenshotServerWorkflow.Contract/IServerWorkflow.cs b/Logic/Business/ScreenshotServerWorkflow.Contract/IServerWorkflow.cs index 0356d83..2a94876 100644 --- a/Logic/Business/ScreenshotServerWorkflow.Contract/IServerWorkflow.cs +++ b/Logic/Business/ScreenshotServerWorkflow.Contract/IServerWorkflow.cs @@ -10,6 +10,8 @@ namespace Logic.Business.ScreenshotServerWorkflow.Contract public interface IServerWorkflow { event EventHandler ScreenshotSent; - void Start(); + void StartSendPrimaryScreen(); + void StartSendScreen(); + void StartSendScreenList(); } } diff --git a/Logic/Business/ScreenshotServerWorkflow/ServerWorkflow.cs b/Logic/Business/ScreenshotServerWorkflow/ServerWorkflow.cs index e29dfbc..45646ed 100644 --- a/Logic/Business/ScreenshotServerWorkflow/ServerWorkflow.cs +++ b/Logic/Business/ScreenshotServerWorkflow/ServerWorkflow.cs @@ -26,11 +26,21 @@ private void ScreenshotServer_ScreenshotSent(object sender, Bitmap e) this.ScreenshotSent?.Invoke(sender, e); } - public void Start() + public void StartSendPrimaryScreen() { - this.screenshotServer.Start(CrossCutting.DataClasses.ConnectionSettings.PipeName, - CrossCutting.DataClasses.ScreenshotOptions.MaxWidth, + this.screenshotServer.StartSendPrimaryScreen(CrossCutting.DataClasses.ScreenshotOptions.MaxWidth, CrossCutting.DataClasses.ScreenshotOptions.MaxHeight); } + + public void StartSendScreen() + { + this.screenshotServer.StartSendScreen(CrossCutting.DataClasses.ScreenshotOptions.MaxWidth, + CrossCutting.DataClasses.ScreenshotOptions.MaxHeight); + } + + public void StartSendScreenList() + { + this.screenshotServer.StartSendScreenList(); + } } } diff --git a/Logic/Domain/Client.Contract/Client.Contract.csproj b/Logic/Domain/Client.Contract/Client.Contract.csproj index 08ace81..3a02dec 100644 --- a/Logic/Domain/Client.Contract/Client.Contract.csproj +++ b/Logic/Domain/Client.Contract/Client.Contract.csproj @@ -45,5 +45,11 @@ + + + {22fee8c4-3711-45e8-8085-02754e1eb77f} + DataClasses + + \ No newline at end of file diff --git a/Logic/Domain/Client.Contract/IScreenshotClient.cs b/Logic/Domain/Client.Contract/IScreenshotClient.cs index 47a1df1..5364622 100644 --- a/Logic/Domain/Client.Contract/IScreenshotClient.cs +++ b/Logic/Domain/Client.Contract/IScreenshotClient.cs @@ -1,4 +1,5 @@ -using System; +using CrossCutting.DataClasses; +using System; using System.Collections.Generic; using System.Drawing; using System.Linq; @@ -9,6 +10,8 @@ namespace Logic.Foundation.Client.Contract { public interface IScreenshotClient { - Bitmap GetScreenshot(string target, string name); + Bitmap GetScreenshot(string target); + Bitmap GetScreenshot(string target, ScreenInformation screenInformation); + IReadOnlyList GetScreenInformationList(string target); } } diff --git a/Logic/Domain/Client/Client.csproj b/Logic/Domain/Client/Client.csproj index 8115e3a..967f4bf 100644 --- a/Logic/Domain/Client/Client.csproj +++ b/Logic/Domain/Client/Client.csproj @@ -46,6 +46,10 @@ + + {22FEE8C4-3711-45E8-8085-02754E1EB77F} + DataClasses + {4a594eba-482e-4a2d-8ce0-7aec059615ea} Encodings.Contract @@ -54,6 +58,10 @@ {67d18de8-9eb0-4746-a3ea-ec1bc9e433b7} Io.Contract + + {e428141b-971f-495e-bf23-277433eb8e32} + Serialization.Contract + {f7ec64a7-f348-41f7-ab6d-6efb6f2054c0} Client.Contract diff --git a/Logic/Domain/Client/ScreenshotClient.cs b/Logic/Domain/Client/ScreenshotClient.cs index 45b5dd5..fd03c67 100644 --- a/Logic/Domain/Client/ScreenshotClient.cs +++ b/Logic/Domain/Client/ScreenshotClient.cs @@ -1,6 +1,8 @@ -using Logic.Foundation.Client.Contract; +using CrossCutting.DataClasses; +using Logic.Foundation.Client.Contract; using Logic.Foundation.Encodings.Contract; using Logic.Foundation.Io.Contract; +using Logic.Foundation.Serialization.Contract; using System; using System.Collections.Generic; using System.Drawing; @@ -15,16 +17,49 @@ public class ScreenshotClient : IScreenshotClient { private readonly ISender sender; private readonly IBinaryDecoder binaryDecoder; - public ScreenshotClient(ISender sender, IBinaryDecoder binaryDecoder) + private readonly ISerializer serializer; + private readonly IDeserializer deserializer; + + public ScreenshotClient(ISender sender, IBinaryDecoder binaryDecoder, + ISerializer serializer, IDeserializer deserializer) { this.sender = sender; this.binaryDecoder = binaryDecoder; + this.serializer = serializer; + this.deserializer = deserializer; + } + + public IReadOnlyList GetScreenInformationList(string target) + { + string result = this.sender.Send(target, + ConnectionSettings.ScreenListPipeName, + "GimmeAScreenshotPlease"); + List screenInformationList + = this.deserializer.Deserialize>(result); + return screenInformationList; + } + + public Bitmap GetScreenshot(string target) + { + string result = this.sender.Send(target, + ConnectionSettings.PrimaryScreenPipeName, + "GimmeAScreenshotPlease"); + Bitmap bitmap = GetBitmapFromResponse(result); + return bitmap; + } + + public Bitmap GetScreenshot(string target, ScreenInformation screenInformation) + { + string text = this.serializer.Serialize(screenInformation); + string result = this.sender.Send(target, + ConnectionSettings.ScreenPipeName, text); + Bitmap bitmap = GetBitmapFromResponse(result); + return bitmap; } - public Bitmap GetScreenshot(string target, string name) + private Bitmap GetBitmapFromResponse(string response) { - string result = this.sender.Send(target, name, "GimmeAScreenshotPlease"); - byte[] arr = this.binaryDecoder.DecodePlainText(result); + byte[] arr = this.binaryDecoder.DecodePlainText(response); MemoryStream ms = new MemoryStream(arr); Bitmap bitmap = new Bitmap(ms); diff --git a/Logic/Domain/Server.Contract/IScreenshotServer.cs b/Logic/Domain/Server.Contract/IScreenshotServer.cs index d04e6c5..08352f8 100644 --- a/Logic/Domain/Server.Contract/IScreenshotServer.cs +++ b/Logic/Domain/Server.Contract/IScreenshotServer.cs @@ -11,6 +11,8 @@ namespace Logic.Foundation.Server.Contract public interface IScreenshotServer { event EventHandler ScreenshotSent; - void Start(string name, int maxWidth, int maxHeight); + void StartSendPrimaryScreen(int maxWidth, int maxHeight); + void StartSendScreen(int maxWidth, int maxHeight); + void StartSendScreenList(); } } diff --git a/Logic/Domain/Server/ScreenshotServer.cs b/Logic/Domain/Server/ScreenshotServer.cs index 51193a1..a59c419 100644 --- a/Logic/Domain/Server/ScreenshotServer.cs +++ b/Logic/Domain/Server/ScreenshotServer.cs @@ -1,6 +1,8 @@ -using Logic.Foundation.Encodings.Contract; +using CrossCutting.DataClasses; +using Logic.Foundation.Encodings.Contract; using Logic.Foundation.Graphics.Contract; using Logic.Foundation.Io.Contract; +using Logic.Foundation.Serialization.Contract; using Logic.Foundation.Server.Contract; using System; using System.Collections.Generic; @@ -10,6 +12,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace Logic.Foundation.Server { @@ -19,37 +22,70 @@ public class ScreenshotServer : IScreenshotServer private readonly IReceiver receiver; private readonly IResize resize; private readonly IBinaryEncoder binaryEncoder; + private readonly ISerializer serializer; + private readonly IDeserializer deserializer; public event EventHandler ScreenshotSent; public ScreenshotServer(IScreenshot screenshot, IReceiver receiver, IResize resize, - IBinaryEncoder binaryEncoder) + IBinaryEncoder binaryEncoder, ISerializer serializer, IDeserializer deserializer) { this.screenshot = screenshot; this.receiver = receiver; this.resize = resize; this.binaryEncoder = binaryEncoder; + this.serializer = serializer; + this.deserializer = deserializer; } - public void Start(string name, int maxWidth, int maxHeight) + public void StartSendPrimaryScreen(int maxWidth, int maxHeight) { string Send(string text) { - using (Bitmap bitmap = this.screenshot.GetFullScreen()) + string base64 = GetScreenshotAsText(this.screenshot.GetPrimaryScreen(), maxWidth, maxHeight); + return base64; + } + this.receiver.Start(ConnectionSettings.PrimaryScreenPipeName, Send); + } + + public void StartSendScreen(int maxWidth, int maxHeight) + { + string Send(string text) + { + ScreenInformation screenInformation = this.deserializer.Deserialize(text); + string base64 = GetScreenshotAsText(this.screenshot.GetScreen(screenInformation.Index), maxWidth, maxHeight); + return base64; + } + this.receiver.Start(ConnectionSettings.ScreenPipeName, Send); + } + + public void StartSendScreenList() + { + string Send(string text) + { + IReadOnlyList screenList = this.screenshot.GetScreenList(); + List screenInformationList = screenList.Select((x, i) => new ScreenInformation(i, x.DeviceName)).ToList(); + string returnValue = this.serializer.Serialize(screenInformationList); + return returnValue; + } + this.receiver.Start(ConnectionSettings.ScreenListPipeName, Send); + } + + private string GetScreenshotAsText(Bitmap screenshot, int maxWidth, int maxHeight) + { + using (Bitmap bitmap = screenshot) + { + using (MemoryStream ms = new MemoryStream()) { - using (MemoryStream ms = new MemoryStream()) + using (Bitmap newImage = this.resize.ResizeImage(bitmap, maxWidth, maxHeight)) { - using (Bitmap newImage = this.resize.ResizeImage(bitmap, maxWidth, maxHeight)) - { - ScreenshotSent?.Invoke(this, new Bitmap(newImage)); - newImage.Save(ms, ImageFormat.Jpeg); - string base64 = this.binaryEncoder.GetAsPlainText(ms.GetBuffer()); - return base64; - } + ScreenshotSent?.Invoke(this, new Bitmap(newImage)); + newImage.Save(ms, ImageFormat.Jpeg); + string base64 = this.binaryEncoder.GetAsPlainText(ms.GetBuffer()); + return base64; } } } - this.receiver.Start(name, Send); } } } diff --git a/Logic/Domain/Server/Server.csproj b/Logic/Domain/Server/Server.csproj index 967e261..5a5ed9e 100644 --- a/Logic/Domain/Server/Server.csproj +++ b/Logic/Domain/Server/Server.csproj @@ -34,6 +34,7 @@ + @@ -46,6 +47,10 @@ + + {22fee8c4-3711-45e8-8085-02754e1eb77f} + DataClasses + {4a594eba-482e-4a2d-8ce0-7aec059615ea} Encodings.Contract @@ -58,6 +63,10 @@ {67d18de8-9eb0-4746-a3ea-ec1bc9e433b7} Io.Contract + + {e428141b-971f-495e-bf23-277433eb8e32} + Serialization.Contract + {95553f46-8fa3-4126-926a-be11fe8b4285} Server.Contract diff --git a/Logic/Foundation/Graphics.Contract/Graphics.Contract.csproj b/Logic/Foundation/Graphics.Contract/Graphics.Contract.csproj index 60a7ca4..80caecd 100644 --- a/Logic/Foundation/Graphics.Contract/Graphics.Contract.csproj +++ b/Logic/Foundation/Graphics.Contract/Graphics.Contract.csproj @@ -34,6 +34,7 @@ + diff --git a/Logic/Foundation/Graphics.Contract/IScreenshot.cs b/Logic/Foundation/Graphics.Contract/IScreenshot.cs index 738a825..a0da9fe 100644 --- a/Logic/Foundation/Graphics.Contract/IScreenshot.cs +++ b/Logic/Foundation/Graphics.Contract/IScreenshot.cs @@ -4,11 +4,15 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Windows.Forms; namespace Logic.Foundation.Graphics.Contract { public interface IScreenshot { - Bitmap GetFullScreen(); + IReadOnlyList GetScreenList(); + Bitmap GetPrimaryScreen(); + Bitmap GetScreen(Screen screen); + Bitmap GetScreen(int screenIndex); } } diff --git a/Logic/Foundation/Graphics/Screenshot.cs b/Logic/Foundation/Graphics/Screenshot.cs index c73dc4b..bca51f3 100644 --- a/Logic/Foundation/Graphics/Screenshot.cs +++ b/Logic/Foundation/Graphics/Screenshot.cs @@ -12,25 +12,45 @@ namespace Logic.Foundation.Graphics { public class Screenshot : IScreenshot { - public Bitmap GetFullScreen() + public Bitmap GetPrimaryScreen() + { + return GetScreen(Screen.PrimaryScreen); + } + + public Bitmap GetScreen(Screen screen) { //Create a new bitmap. - Bitmap bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, - Screen.PrimaryScreen.Bounds.Height, + Bitmap bmpScreenshot = new Bitmap(screen.Bounds.Width, + screen.Bounds.Height, PixelFormat.Format32bppArgb); // Create a graphics object from the bitmap. System.Drawing.Graphics gfxScreenshot = System.Drawing.Graphics.FromImage(bmpScreenshot); // Take the screenshot from the upper left corner to the right bottom corner. - gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, - Screen.PrimaryScreen.Bounds.Y, + gfxScreenshot.CopyFromScreen(screen.Bounds.X, + screen.Bounds.Y, 0, 0, - Screen.PrimaryScreen.Bounds.Size, + screen.Bounds.Size, CopyPixelOperation.SourceCopy); return bmpScreenshot; } + + public Bitmap GetScreen(int screenIndex) + { + IReadOnlyList screenList = this.GetScreenList(); + if ((screenIndex < 0) || (screenIndex >= screenList.Count)) + { + throw new ArgumentOutOfRangeException($"{nameof(screenIndex)} = {screenIndex}"); + } + return GetScreen(screenList[screenIndex]); + } + + public IReadOnlyList GetScreenList() + { + return Screen.AllScreens; + } } } diff --git a/Logic/Foundation/Serialization.Contract/IDeserializer.cs b/Logic/Foundation/Serialization.Contract/IDeserializer.cs new file mode 100644 index 0000000..0fe05e9 --- /dev/null +++ b/Logic/Foundation/Serialization.Contract/IDeserializer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Logic.Foundation.Serialization.Contract +{ + public interface IDeserializer + { + T Deserialize(string text) where T : new(); + } +} diff --git a/Logic/Foundation/Serialization.Contract/ISerializer.cs b/Logic/Foundation/Serialization.Contract/ISerializer.cs new file mode 100644 index 0000000..53f3a0a --- /dev/null +++ b/Logic/Foundation/Serialization.Contract/ISerializer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Logic.Foundation.Serialization.Contract +{ + public interface ISerializer + { + string Serialize(T obj); + } +} diff --git a/Logic/Foundation/Serialization.Contract/Properties/AssemblyInfo.cs b/Logic/Foundation/Serialization.Contract/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..e5a3143 --- /dev/null +++ b/Logic/Foundation/Serialization.Contract/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Serialization.Contract")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Serialization.Contract")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("e428141b-971f-495e-bf23-277433eb8e32")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Logic/Foundation/Serialization.Contract/Serialization.Contract.csproj b/Logic/Foundation/Serialization.Contract/Serialization.Contract.csproj new file mode 100644 index 0000000..336c30d --- /dev/null +++ b/Logic/Foundation/Serialization.Contract/Serialization.Contract.csproj @@ -0,0 +1,49 @@ + + + + + Debug + AnyCPU + {E428141B-971F-495E-BF23-277433EB8E32} + Library + Properties + Logic.Foundation.Serialization.Contract + Serialization.Contract + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Logic/Foundation/Serialization/JsonDeserializer.cs b/Logic/Foundation/Serialization/JsonDeserializer.cs new file mode 100644 index 0000000..0ac29f0 --- /dev/null +++ b/Logic/Foundation/Serialization/JsonDeserializer.cs @@ -0,0 +1,19 @@ +using Logic.Foundation.Serialization.Contract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Logic.Foundation.Serialization +{ + public class JsonDeserializer : IDeserializer + { + public T Deserialize(string text) where T : new() + { + T obj = new T(); + Newtonsoft.Json.JsonConvert.PopulateObject(text, obj); + return obj; + } + } +} diff --git a/Logic/Foundation/Serialization/JsonSerializer.cs b/Logic/Foundation/Serialization/JsonSerializer.cs new file mode 100644 index 0000000..80a3b10 --- /dev/null +++ b/Logic/Foundation/Serialization/JsonSerializer.cs @@ -0,0 +1,17 @@ +using Logic.Foundation.Serialization.Contract; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Logic.Foundation.Serialization +{ + public class JsonSerializer : ISerializer + { + public string Serialize(T obj) + { + return Newtonsoft.Json.JsonConvert.SerializeObject(obj); + } + } +} diff --git a/Logic/Foundation/Serialization/Properties/AssemblyInfo.cs b/Logic/Foundation/Serialization/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..b252de6 --- /dev/null +++ b/Logic/Foundation/Serialization/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// Allgemeine Informationen über eine Assembly werden über die folgenden +// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern, +// die einer Assembly zugeordnet sind. +[assembly: AssemblyTitle("Serialization")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Serialization")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly +// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von +// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen. +[assembly: ComVisible(false)] + +// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird +[assembly: Guid("6b38a64d-27b0-4f98-ba53-4204b4394c58")] + +// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten: +// +// Hauptversion +// Nebenversion +// Buildnummer +// Revision +// +// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden, +// indem Sie "*" wie unten gezeigt eingeben: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/Logic/Foundation/Serialization/Serialization.csproj b/Logic/Foundation/Serialization/Serialization.csproj new file mode 100644 index 0000000..36601fb --- /dev/null +++ b/Logic/Foundation/Serialization/Serialization.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {6B38A64D-27B0-4F98-BA53-4204B4394C58} + Library + Properties + Logic.Foundation.Serialization + Serialization + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\..\..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + {e428141b-971f-495e-bf23-277433eb8e32} + Serialization.Contract + + + + + + + \ No newline at end of file diff --git a/Logic/Foundation/Serialization/packages.config b/Logic/Foundation/Serialization/packages.config new file mode 100644 index 0000000..a9de8b5 --- /dev/null +++ b/Logic/Foundation/Serialization/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.Designer.cs b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.Designer.cs index 30b7be0..947f178 100644 --- a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.Designer.cs +++ b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.Designer.cs @@ -40,20 +40,23 @@ private void InitializeComponent() this.panelTop = new System.Windows.Forms.Panel(); this.groupBoxServer = new System.Windows.Forms.GroupBox(); this.groupBoxClient = new System.Windows.Forms.GroupBox(); + this.pbGetScreens = new System.Windows.Forms.Button(); + this.cmbScreenList = new System.Windows.Forms.ComboBox(); + this.screenInformationListBindingSource = new System.Windows.Forms.BindingSource(this.components); ((System.ComponentModel.ISupportInitialize)(this.bindingSourceViewModel)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.pictureBoxScreenshot)).BeginInit(); this.panelTop.SuspendLayout(); this.groupBoxServer.SuspendLayout(); this.groupBoxClient.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.screenInformationListBindingSource)).BeginInit(); this.SuspendLayout(); // // label1 // this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(7, 30); - this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0); + this.label1.Location = new System.Drawing.Point(5, 24); this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(54, 17); + this.label1.Size = new System.Drawing.Size(41, 13); this.label1.TabIndex = 0; this.label1.Text = "Target:"; // @@ -61,10 +64,9 @@ private void InitializeComponent() // this.dfTarget.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.bindingSourceViewModel, "Target", true)); this.dfTarget.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.bindingSourceViewModel, "SendEnabled", true)); - this.dfTarget.Location = new System.Drawing.Point(69, 23); - this.dfTarget.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.dfTarget.Location = new System.Drawing.Point(52, 19); this.dfTarget.Name = "dfTarget"; - this.dfTarget.Size = new System.Drawing.Size(132, 22); + this.dfTarget.Size = new System.Drawing.Size(100, 20); this.dfTarget.TabIndex = 1; // // bindingSourceViewModel @@ -74,10 +76,9 @@ private void InitializeComponent() // buttonListen // this.buttonListen.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.bindingSourceViewModel, "SendEnabled", true)); - this.buttonListen.Location = new System.Drawing.Point(8, 23); - this.buttonListen.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.buttonListen.Location = new System.Drawing.Point(6, 19); this.buttonListen.Name = "buttonListen"; - this.buttonListen.Size = new System.Drawing.Size(100, 28); + this.buttonListen.Size = new System.Drawing.Size(75, 23); this.buttonListen.TabIndex = 2; this.buttonListen.Text = "Listen"; this.buttonListen.UseVisualStyleBackColor = true; @@ -86,10 +87,9 @@ private void InitializeComponent() // pbGet // this.pbGet.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.bindingSourceViewModel, "SendEnabled", true)); - this.pbGet.Location = new System.Drawing.Point(211, 21); - this.pbGet.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pbGet.Location = new System.Drawing.Point(158, 17); this.pbGet.Name = "pbGet"; - this.pbGet.Size = new System.Drawing.Size(100, 28); + this.pbGet.Size = new System.Drawing.Size(75, 23); this.pbGet.TabIndex = 3; this.pbGet.Text = "Get"; this.pbGet.UseVisualStyleBackColor = true; @@ -99,10 +99,9 @@ private void InitializeComponent() // this.pictureBoxScreenshot.DataBindings.Add(new System.Windows.Forms.Binding("Image", this.bindingSourceViewModel, "Screenshot", true)); this.pictureBoxScreenshot.Dock = System.Windows.Forms.DockStyle.Fill; - this.pictureBoxScreenshot.Location = new System.Drawing.Point(0, 71); - this.pictureBoxScreenshot.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.pictureBoxScreenshot.Location = new System.Drawing.Point(0, 58); this.pictureBoxScreenshot.Name = "pictureBoxScreenshot"; - this.pictureBoxScreenshot.Size = new System.Drawing.Size(1067, 483); + this.pictureBoxScreenshot.Size = new System.Drawing.Size(800, 392); this.pictureBoxScreenshot.TabIndex = 4; this.pictureBoxScreenshot.TabStop = false; // @@ -112,46 +111,70 @@ private void InitializeComponent() this.panelTop.Controls.Add(this.groupBoxClient); this.panelTop.Dock = System.Windows.Forms.DockStyle.Top; this.panelTop.Location = new System.Drawing.Point(0, 0); - this.panelTop.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.panelTop.Name = "panelTop"; - this.panelTop.Size = new System.Drawing.Size(1067, 71); + this.panelTop.Size = new System.Drawing.Size(800, 58); this.panelTop.TabIndex = 5; // // groupBoxServer // this.groupBoxServer.Controls.Add(this.buttonListen); - this.groupBoxServer.Location = new System.Drawing.Point(395, 4); - this.groupBoxServer.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.groupBoxServer.Location = new System.Drawing.Point(621, 3); this.groupBoxServer.Name = "groupBoxServer"; - this.groupBoxServer.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.groupBoxServer.Size = new System.Drawing.Size(124, 60); + this.groupBoxServer.Size = new System.Drawing.Size(93, 49); this.groupBoxServer.TabIndex = 7; this.groupBoxServer.TabStop = false; this.groupBoxServer.Text = "Server"; // // groupBoxClient // + this.groupBoxClient.Controls.Add(this.pbGetScreens); + this.groupBoxClient.Controls.Add(this.cmbScreenList); this.groupBoxClient.Controls.Add(this.dfTarget); this.groupBoxClient.Controls.Add(this.label1); this.groupBoxClient.Controls.Add(this.pbGet); - this.groupBoxClient.Location = new System.Drawing.Point(4, 4); - this.groupBoxClient.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); + this.groupBoxClient.Location = new System.Drawing.Point(3, 3); this.groupBoxClient.Name = "groupBoxClient"; - this.groupBoxClient.Padding = new System.Windows.Forms.Padding(4, 4, 4, 4); - this.groupBoxClient.Size = new System.Drawing.Size(325, 60); + this.groupBoxClient.Size = new System.Drawing.Size(534, 49); this.groupBoxClient.TabIndex = 6; this.groupBoxClient.TabStop = false; this.groupBoxClient.Text = "Client"; // + // pbGetScreens + // + this.pbGetScreens.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.bindingSourceViewModel, "SendEnabled", true)); + this.pbGetScreens.Location = new System.Drawing.Point(272, 17); + this.pbGetScreens.Name = "pbGetScreens"; + this.pbGetScreens.Size = new System.Drawing.Size(75, 23); + this.pbGetScreens.TabIndex = 3; + this.pbGetScreens.Text = "Get screens"; + this.pbGetScreens.UseVisualStyleBackColor = true; + this.pbGetScreens.Click += new System.EventHandler(this.pbGetScreens_Click); + // + // cmbScreenList + // + this.cmbScreenList.DataBindings.Add(new System.Windows.Forms.Binding("Enabled", this.bindingSourceViewModel, "SendEnabled", true)); + this.cmbScreenList.DataBindings.Add(new System.Windows.Forms.Binding("SelectedItem", this.bindingSourceViewModel, "ScreenInformationEditValue", true)); + this.cmbScreenList.DataSource = this.screenInformationListBindingSource; + this.cmbScreenList.DisplayMember = "Name"; + this.cmbScreenList.FormattingEnabled = true; + this.cmbScreenList.Location = new System.Drawing.Point(353, 18); + this.cmbScreenList.Name = "cmbScreenList"; + this.cmbScreenList.Size = new System.Drawing.Size(175, 21); + this.cmbScreenList.TabIndex = 4; + // + // screenInformationListBindingSource + // + this.screenInformationListBindingSource.DataMember = "ScreenInformationList"; + this.screenInformationListBindingSource.DataSource = this.bindingSourceViewModel; + // // GimmeAScreenshotPleaseForm // - this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(1067, 554); + this.ClientSize = new System.Drawing.Size(800, 450); this.Controls.Add(this.pictureBoxScreenshot); this.Controls.Add(this.panelTop); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); - this.Margin = new System.Windows.Forms.Padding(4, 4, 4, 4); this.Name = "GimmeAScreenshotPleaseForm"; this.Text = "GimmeAScreenshotPlease"; ((System.ComponentModel.ISupportInitialize)(this.bindingSourceViewModel)).EndInit(); @@ -160,6 +183,7 @@ private void InitializeComponent() this.groupBoxServer.ResumeLayout(false); this.groupBoxClient.ResumeLayout(false); this.groupBoxClient.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.screenInformationListBindingSource)).EndInit(); this.ResumeLayout(false); } @@ -175,6 +199,9 @@ private void InitializeComponent() private System.Windows.Forms.Panel panelTop; private System.Windows.Forms.GroupBox groupBoxClient; private System.Windows.Forms.GroupBox groupBoxServer; + private System.Windows.Forms.Button pbGetScreens; + private System.Windows.Forms.ComboBox cmbScreenList; + private System.Windows.Forms.BindingSource screenInformationListBindingSource; } } diff --git a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.cs b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.cs index 9c4e339..73170f3 100644 --- a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.cs +++ b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.cs @@ -30,5 +30,10 @@ private void buttonListen_Click(object sender, EventArgs e) { this.viewModel.StartServer(); } + + private void pbGetScreens_Click(object sender, EventArgs e) + { + this.viewModel.GetScreenList(); + } } } diff --git a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.resx b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.resx index 7e33085..88eda7a 100644 --- a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.resx +++ b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseForm.resx @@ -120,6 +120,9 @@ 17, 17 + + 394, 17 + diff --git a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseUI.csproj b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseUI.csproj index f916b8c..17f15b3 100644 --- a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseUI.csproj +++ b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseUI.csproj @@ -86,6 +86,10 @@ + + {22fee8c4-3711-45e8-8085-02754e1eb77f} + DataClasses + {09a8c334-e806-4777-9aed-b43257e27f56} ScreenshotClientWorkflow.Contract @@ -142,6 +146,14 @@ {45e3cf2d-41ee-408d-b44d-2f27a79aa826} Io + + {e428141b-971f-495e-bf23-277433eb8e32} + Serialization.Contract + + + {6b38a64d-27b0-4f98-ba53-4204b4394c58} + Serialization + diff --git a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseViewModel.cs b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseViewModel.cs index 50b2073..4be19c7 100644 --- a/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseViewModel.cs +++ b/UI/GimmeAScreenshotPleaseUI/GimmeAScreenshotPleaseViewModel.cs @@ -1,4 +1,5 @@ -using Logic.Business.ScreenshotClientWorkflow; +using CrossCutting.DataClasses; +using Logic.Business.ScreenshotClientWorkflow; using Logic.Business.ScreenshotClientWorkflow.Contract; using Logic.Business.ScreenshotServerWorkflow; using Logic.Business.ScreenshotServerWorkflow.Contract; @@ -6,6 +7,7 @@ using Logic.Foundation.Encodings; using Logic.Foundation.Graphics; using Logic.Foundation.Io; +using Logic.Foundation.Serialization; using Logic.Foundation.Server; using System; using System.Collections.Generic; @@ -26,6 +28,7 @@ public class GimmeAScreenshotPleaseViewModel : INotifyPropertyChanged private readonly IServerWorkflow serverWorkflow; public string Target { get => target; set { if (Target != value) { target = value; OnPropertyChanged(); } } } + private string target = ""; public bool SendEnabled { get => sendEnabled; set { if (SendEnabled != value) { sendEnabled = value; OnPropertyChanged(); } } } private bool sendEnabled = true; @@ -35,14 +38,17 @@ public class GimmeAScreenshotPleaseViewModel : INotifyPropertyChanged public event PropertyChangedEventHandler PropertyChanged; + public BindingList ScreenInformationList { get; set; } = new BindingList(); + public ScreenInformation ScreenInformationEditValue { get; set; } + private Control control; public GimmeAScreenshotPleaseViewModel() { this.clientWorkflow = new ClientWorkflow(new ScreenshotClient(new NamedPipeSender(), - new BinaryDecoder())); + new BinaryDecoder(), new JsonSerializer(), new JsonDeserializer())); this.serverWorkflow = new ServerWorkflow(new ScreenshotServer(new Screenshot(), new NamedPipeReceiver(), new Resize(), - new BinaryEncoder())); + new BinaryEncoder(), new JsonSerializer(), new JsonDeserializer())); this.serverWorkflow.ScreenshotSent += ServerWorkflow_ScreenshotSent; this.Target = Properties.Settings.Default.Target; @@ -73,13 +79,40 @@ public void StartServer() this.SendEnabled = false; Task.Factory.StartNew(() => { - this.serverWorkflow.Start(); + this.serverWorkflow.StartSendPrimaryScreen(); + }); + Task.Factory.StartNew(() => + { + this.serverWorkflow.StartSendScreen(); + }); + Task.Factory.StartNew(() => + { + this.serverWorkflow.StartSendScreenList(); }); } public void GetScreenShot() { - this.Screenshot = this.clientWorkflow.GetScreenshot(this.Target); + if ((ScreenInformationEditValue?.Index ?? -1) >= 0) + { + this.Screenshot = this.clientWorkflow.GetScreenshotForScreen(this.Target, this.ScreenInformationEditValue); + } + else + { + this.Screenshot = this.clientWorkflow.GetScreenshotPrimaryScreen(this.Target); + } + } + + public void GetScreenList() + { + IReadOnlyList screenInformationList = this.clientWorkflow.GetScreenInformationList(this.Target); + this.ScreenInformationList.Clear(); + this.ScreenInformationList.Add(new ScreenInformation(-1, string.Empty)); + foreach (ScreenInformation screenInformation in screenInformationList) + { + this.ScreenInformationList.Add(screenInformation); + } + this.ScreenInformationEditValue = this.ScreenInformationList.First(); } private void OnPropertyChanged([CallerMemberName] string propName = "")