From d967b4b37644ab6aedac36539f8f6fa5cf3547f2 Mon Sep 17 00:00:00 2001 From: Roy Ben-Shabat Date: Mon, 6 May 2019 18:01:50 +0300 Subject: Working on TCC.. --- .../Visual_Studio/Tango.UnitTesting/App.config | 20 ++++++----- .../Tango.UnitTesting/SendGrid/SendGrid_TST.cs | 39 ++++++++++++++++++++++ .../Tango.UnitTesting/Tango.UnitTesting.csproj | 22 ++++++++++-- .../Tango.UnitTesting/packages.config | 6 ++++ 4 files changed, 77 insertions(+), 10 deletions(-) create mode 100644 Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Visual_Studio/Tango.UnitTesting/App.config b/Software/Visual_Studio/Tango.UnitTesting/App.config index 1261bcbe9..0490d020e 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/App.config +++ b/Software/Visual_Studio/Tango.UnitTesting/App.config @@ -63,7 +63,7 @@ - + @@ -71,27 +71,27 @@ - + - + - + - + - + - + @@ -107,7 +107,7 @@ - + @@ -117,6 +117,10 @@ + + + + diff --git a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs new file mode 100644 index 000000000..785fa42bf --- /dev/null +++ b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs @@ -0,0 +1,39 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SendGrid; +using SendGrid.Helpers.Mail; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.UnitTesting.SendGrid +{ + [TestClass] + [TestCategory("SendGrid")] + public class SendGrid_TST + { + private const string KEY = "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"; + + [TestMethod] + public void Send_Simple_Email() + { + var client = new SendGridClient(KEY); + var from = new EmailAddress("test@example.com", "Example User"); + var subject = "Sending with SendGrid is Fun"; + var to = new EmailAddress("roy@twine-s.com", "Roy Ben Shabat"); + var plainTextContent = "and easy to do anywhere, even with C#"; + var htmlContent = "
and easy to do anywhere, even with C#"; + var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); + + var bytes = File.ReadAllBytes(@"D:\Downloads\Twine TWN Spec (3).pdf"); + var file = Convert.ToBase64String(bytes); + msg.AddAttachment("Twine Spec.pdf", file, "application/pdf"); + + var response = client.SendEmailAsync(msg).GetAwaiter().GetResult(); + + Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Accepted); + } + } +} diff --git a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj index 6fd23451d..c7a2cc451 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj +++ b/Software/Visual_Studio/Tango.UnitTesting/Tango.UnitTesting.csproj @@ -84,6 +84,9 @@ ..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll + + ..\packages\Sendgrid.9.11.0\lib\net452\SendGrid.dll + @@ -103,10 +106,24 @@ True - + + ..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll + ..\packages\Microsoft.AspNet.WebApi.Client.5.2.3\lib\net45\System.Net.Http.Formatting.dll + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net461\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + ..\packages\Microsoft.AspNet.WebApi.Core.5.2.3\lib\net45\System.Web.Http.dll @@ -126,6 +143,7 @@ + @@ -289,7 +307,7 @@ - + \ No newline at end of file diff --git a/Software/Visual_Studio/Tango.UnitTesting/packages.config b/Software/Visual_Studio/Tango.UnitTesting/packages.config index e3fc2d3b6..f6feb1f49 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/packages.config +++ b/Software/Visual_Studio/Tango.UnitTesting/packages.config @@ -11,9 +11,15 @@ + + + + + + \ No newline at end of file -- cgit v1.3.1 From 5541336e213bbd54d9f408de3856db9654e82150 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Wed, 8 May 2019 08:50:31 +0300 Subject: Working on TCC... --- .../Android_Studio/ColorCapture/app/build.gradle | 2 +- .../views/loading/LoadingActivityVM.java | 2 +- .../views/register/RegisterFragmentVM.java | 4 +- .../views/result/ResultFragmentVM.java | 1 - .../sendtomachine/SendToMachineFragmentVM.java | 30 ++++++++--- .../com/twine/colorcapture/web/ITCCService.java | 8 --- .../com/twine/colorcapture/web/TCCService.java | 28 +--------- Software/DB/TCC/TCC.mdf | Bin 8388608 -> 8388608 bytes Software/DB/TCC/TCC_log.ldf | Bin 8388608 -> 8388608 bytes Software/DB/Tango.mdf | Bin 75497472 -> 75497472 bytes Software/DB/Tango_log.ldf | Bin 22675456 -> 22675456 bytes .../Controllers/ColorDetectionController.cs | 19 ++++--- .../Tango.UnitTesting/SendGrid/SendGrid_TST.cs | 58 +++++++++++++++++++++ 13 files changed, 98 insertions(+), 54 deletions(-) (limited to 'Software/Visual_Studio/Tango.UnitTesting') diff --git a/Software/Android_Studio/ColorCapture/app/build.gradle b/Software/Android_Studio/ColorCapture/app/build.gradle index 3aa149370..0ca125d7f 100644 --- a/Software/Android_Studio/ColorCapture/app/build.gradle +++ b/Software/Android_Studio/ColorCapture/app/build.gradle @@ -31,7 +31,7 @@ android { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - buildConfigField "String", "WEB_SERVICE_ADDRESS", "\"http://twinetcc.azurewebsites.net/api/\"" + buildConfigField "String", "WEB_SERVICE_ADDRESS", "\"http://tcc.twine-srv.com/api/\"" buildConfigField "String", "WEB_SERVICE_APP_ID", "\"Tdf793i4ughsiduf8749509237885ehgfdlkghlT\"" } diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/loading/LoadingActivityVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/loading/LoadingActivityVM.java index 5f2a0e8ac..f2bbd6413 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/loading/LoadingActivityVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/loading/LoadingActivityVM.java @@ -60,7 +60,7 @@ public class LoadingActivityVM extends ViewModelBase new Task.TaskBuilder().setAction(() -> { tccService.getDefinition(); - ThreadingUtils.sleep(3000); + ThreadingUtils.sleep(1000); }).setContinueWith(() -> { initialized = true; diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/register/RegisterFragmentVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/register/RegisterFragmentVM.java index e328a4b77..ffeda3f84 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/register/RegisterFragmentVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/register/RegisterFragmentVM.java @@ -56,7 +56,7 @@ public class RegisterFragmentVM extends ViewModelBase try { - ThreadingUtils.sleep(5000); + ThreadingUtils.sleep(2000); MachineRegistrationResponse response = tccService.register(serialNumber.get()); @@ -68,8 +68,6 @@ public class RegisterFragmentVM extends ViewModelBase notificationProvider.showSuccess("Registering your system", "Your device has been successfully\nregistered.", (e) -> { - tccService.setRegistered(true); - tccService.setOrganizationMachines(response.getOrganizationMachines()); navigationProvider.navigateBack(); }); } diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/result/ResultFragmentVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/result/ResultFragmentVM.java index a4b1bd2e7..490c9e2b9 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/result/ResultFragmentVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/result/ResultFragmentVM.java @@ -132,7 +132,6 @@ public class ResultFragmentVM extends ViewModelBase implements try { isMachineRegistred.set(tccService.getDefinition().isRegistered()); - boolean a = isMachineRegistred.get(); } catch (Exception e) { diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtomachine/SendToMachineFragmentVM.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtomachine/SendToMachineFragmentVM.java index a51d0eb71..9c6d7003e 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtomachine/SendToMachineFragmentVM.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/views/sendtomachine/SendToMachineFragmentVM.java @@ -53,23 +53,37 @@ public class SendToMachineFragmentVM extends ViewModelBase x.equals(machine.getSerialNumber()))) + try { - invokeUI(() -> + if (stream(tccService.getDefinition().getOrganizationMachines()).any(x -> x.equals(machine.getSerialNumber()))) { - machines.remove(machine); - }); + invokeUI(() -> + { + machines.remove(machine); + }); + } + } + catch (Exception e) + { + e.printStackTrace(); } } private void onMachineDiscovered(Object o, ExternalBridgeMachine machine) { - if (stream(tccService.getOrganizationMachines()).any(x -> x.equals(machine.getSerialNumber()))) + try { - invokeUI(() -> + if (stream(tccService.getDefinition().getOrganizationMachines()).any(x -> x.equals(machine.getSerialNumber()))) { - machines.add(0, machine); - }); + invokeUI(() -> + { + machines.add(0, machine); + }); + } + } + catch (Exception e) + { + e.printStackTrace(); } } diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/ITCCService.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/ITCCService.java index 8e39fff8e..9cca30b73 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/ITCCService.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/ITCCService.java @@ -21,12 +21,4 @@ public interface ITCCService MachineRegistrationResponse register(String serialNumber) throws Exception; ResultByEmailResponse sendResultByEmail(ResultByEmailRequest request) throws Exception; - - boolean isRegistered(); - - List getOrganizationMachines(); - - void setRegistered(boolean registered); - - void setOrganizationMachines(List organizationMachines); } diff --git a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/TCCService.java b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/TCCService.java index b56eead39..59fa6f3b5 100644 --- a/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/TCCService.java +++ b/Software/Android_Studio/ColorCapture/app/src/main/java/com/twine/colorcapture/web/TCCService.java @@ -38,8 +38,6 @@ public class TCCService implements ITCCService private IWebServiceAPI webAPI; private LoginResponse loginResponse; private static final String DEVICE_ID_PREF_NAME = "DeviceIdFile"; - private boolean isRegistered; - private List organizationMachines; @Inject public TCCService(IWebServiceAPI webServiceAPI) @@ -61,8 +59,6 @@ public class TCCService implements ITCCService if (response.isSuccessful()) { definition = response.body(); - isRegistered = definition.isRegistered(); - organizationMachines = definition.getOrganizationMachines(); LogManager.log("Definition retrieved.", definition); } @@ -122,8 +118,8 @@ public class TCCService implements ITCCService LogManager.log("Machine registration successful.", r); - isRegistered = true; - organizationMachines = r.getOrganizationMachines(); + definition.setRegistered(true); + definition.setOrganizationMachines(r.getOrganizationMachines()); return r; } else @@ -209,24 +205,4 @@ public class TCCService implements ITCCService throw LogManager.log(new Exception(response.message()), "LogIn request failed."); } } - - public boolean isRegistered() - { - return isRegistered; - } - - public List getOrganizationMachines() - { - return organizationMachines; - } - - public void setRegistered(boolean registered) - { - isRegistered = registered; - } - - public void setOrganizationMachines(List organizationMachines) - { - this.organizationMachines = organizationMachines; - } } diff --git a/Software/DB/TCC/TCC.mdf b/Software/DB/TCC/TCC.mdf index 95bca206e..d66dc8a2c 100644 Binary files a/Software/DB/TCC/TCC.mdf and b/Software/DB/TCC/TCC.mdf differ diff --git a/Software/DB/TCC/TCC_log.ldf b/Software/DB/TCC/TCC_log.ldf index 740a974a0..31a2d0967 100644 Binary files a/Software/DB/TCC/TCC_log.ldf and b/Software/DB/TCC/TCC_log.ldf differ diff --git a/Software/DB/Tango.mdf b/Software/DB/Tango.mdf index 659b32f42..d1c66cc74 100644 Binary files a/Software/DB/Tango.mdf and b/Software/DB/Tango.mdf differ diff --git a/Software/DB/Tango_log.ldf b/Software/DB/Tango_log.ldf index 27cf94e8f..1504d0f5d 100644 Binary files a/Software/DB/Tango_log.ldf and b/Software/DB/Tango_log.ldf differ diff --git a/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs b/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs index f95ff1c05..e2560ff41 100644 --- a/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs +++ b/Software/Visual_Studio/TCC/Tango.TCC.Service/Controllers/ColorDetectionController.cs @@ -196,12 +196,19 @@ namespace Tango.TCC.Service.Controllers ResultByEmailResponse response = new ResultByEmailResponse(); var client = new SendGridClient(TCCServiceConfig.SEND_GRID_API_KEY); - var from = new EmailAddress(request.From); - var subject = "SnapMatch Color Result"; - var to = new EmailAddress(request.To); - var plainTextContent = request.Message; - var htmlContent = $"
{request.Message}."; - var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); + //var from = new EmailAddress(request.From); + //var subject = "SnapMatch Color Result"; + //var to = new EmailAddress(request.To); + SendGridMessage msg = new SendGridMessage(); + msg.SetFrom(request.From); + msg.AddTo(request.To); + msg.Subject = "SnapMatch Color Result"; + + + + //var plainTextContent = request.Message; + //var htmlContent = $"
{request.Message}."; + //var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent); DetectionColorFile file = new DetectionColorFile(); file.RawColor = request.DetectionResponse.RawColor; diff --git a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs index 785fa42bf..9465676ef 100644 --- a/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs +++ b/Software/Visual_Studio/Tango.UnitTesting/SendGrid/SendGrid_TST.cs @@ -3,10 +3,14 @@ using SendGrid; using SendGrid.Helpers.Mail; using System; using System.Collections.Generic; +using System.Drawing; +using System.Drawing.Imaging; using System.IO; using System.Linq; +using System.Net; using System.Text; using System.Threading.Tasks; +using Tango.PMR.TCC; namespace Tango.UnitTesting.SendGrid { @@ -35,5 +39,59 @@ namespace Tango.UnitTesting.SendGrid Assert.IsTrue(response.StatusCode == System.Net.HttpStatusCode.Accepted); } + + [TestMethod] + public void Send_Template_Email() + { + var client = new SendGridClient(KEY); + SendGridMessage msg = new SendGridMessage(); + msg.SetFrom("test@example.com"); + msg.AddTo("roy.mail.net@gmail.com"); + msg.Subject = "SnapMatch Color Result"; + msg.SetTemplateId("d-619b8adc604d4f6fa486d7bbc9e3c2cc"); + + Bitmap rect = new Bitmap(80, 80); + using (Graphics g = Graphics.FromImage(rect)) + { + g.Clear(Color.FromArgb(255, 0, 0)); + } + + String image64 = String.Empty; + + using (MemoryStream ms = new MemoryStream()) + { + rect.Save(ms, ImageFormat.Jpeg); + ms.Position = 0; + image64 = Convert.ToBase64String(ms.ToArray()); + } + + var dynamicTemplateData = new ExampleTemplateData + { + Name = "Roy", + Message = "This is my personal note...", + ImageSource = image64, + }; + + msg.SetTemplateData(dynamicTemplateData); + + + DetectionColorFile file = new DetectionColorFile(); + file.RawColor = new DetectionColor() { R = 10, G = 20, B = 30 }; + file.ProcessedColor = new DetectionColor() { R = 11, G = 21, B = 31 }; + + var base64 = Convert.ToBase64String(file.ToBytes()); + msg.AddAttachment("SnapMatch Color.tcc", base64, "application/octet-stream"); + + var result = client.SendEmailAsync(msg).GetAwaiter().GetResult(); + + Assert.IsTrue(result.StatusCode == HttpStatusCode.Accepted); + } + + public class ExampleTemplateData + { + public String Name { get; set; } + public String ImageSource { get; set; } + public String Message { get; set; } + } } } -- cgit v1.3.1