aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.RML/Views/MainView.xaml
blob: e52ac4ece2fd91d9788c40e8f2ecdf2438fce3aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<UserControl x:Class="Tango.MachineStudio.RML.Views.MainView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:global="clr-namespace:Tango.MachineStudio.RML"
             xmlns:vm="clr-namespace:Tango.MachineStudio.RML.ViewModels"
             xmlns:controls="clr-namespace:Tango.SharedUI.Controls;assembly=Tango.SharedUI"
             xmlns:local="clr-namespace:Tango.MachineStudio.RML.Views"
             mc:Ignorable="d" 
             d:DesignHeight="1080" d:DesignWidth="1920" Background="Transparent" d:DataContext="{d:DesignInstance Type=vm:MainViewVM, IsDesignTimeCreatable=False}" DataContext="{x:Static global:ViewModelLocator.MainViewVM}">
    <Grid IsEnabled="{Binding IsFree}">
        <controls:NavigationControl x:Name="navigationControl" TransitionType="Slide">
            <local:RmlsView />
            <local:RmlView/>
        </controls:NavigationControl>
    </Grid>
</UserControl>
/* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Tango.Protobuf;
using System.Threading;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Google.Protobuf;
using Tango.PMR.Jobs;
using Tango.PMR.Common;
using Tango.PMR;
using Tango.Logging;
using Newtonsoft.Json;
using System.Runtime.InteropServices;
using Tango.Core.Helpers;
using System.Text;
using Tango.PMR.Stubs;

namespace Tango.UnitTesting
{
    [TestClass]
    [TestCategory("Protobuf")]
    public class Protobuf_TST
    {
        [DllImport("Tango.ProtoTest.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Calculate")]
        public static extern int CalculateCPP(IntPtr data, int size, ref IntPtr output);

        [DllImport("Tango.ColorLib.dll", CallingConvention = CallingConvention.Cdecl, EntryPoint = "Calculate")]
        public static extern int CalculateC(IntPtr data, int size, ref IntPtr output);

        /// <summary>
        /// Compiles all the whole PMR using all available compilers.
        /// </summary>
        [TestMethod]
        public void Compile_All_PMR()
        {
            var console = Helper.InitializeLogging(true);

            String pmrFolder = Helper.GetPMRPath();

            List<String> tempFolders = new List<string>();

            foreach (var compiler in CompilerFactory.GetAvailableCompilers())
            {
                CompilerFolderResult result = compiler.CompileFolder(pmrFolder);
                String tmpFolder = Helper.GetTempFolderPathAppend(compiler.Language.ToString());
                result.Save(tmpFolder);
                tempFolders.Add(tmpFolder);
            }

            Helper.ShowInExplorer(Directory.GetParent(tempFolders.First()).FullName);

            console.WaitForConsoleExit().Wait();

            foreach (var folder in tempFolders)
            {
                Helper.TryDeleteFolder(folder);
            }
        }

        /// <summary>
        /// Writes and reads a proto message then compares.
        /// </summary>
        [TestMethod]
        public void Read_Write_Message()
        {
            var console = Helper.InitializeLogging(true);

            TangoMessage<Job> container = MessageFactory.CreateTangoMessage<Job>();

            container.Message.Name = "Test Job";

            container.Message.Segments.Add(new Segment()
            {
                Color = new RGB() { R = 1, G = 2, B = 3 },
                Length = 10,
                Name = "Segment 1"
            });

            container.Message.Segments.Add(new Segment()
            {
                Color = new RGB() { R = 10, G = 20, B = 30 },
                Length = 100,
                Name = "Segment 2"
            });

            LogManager.Log("Write Message:" + Environment.NewLine + JsonConvert.SerializeObject(container.Message, Formatting.Indented));

            var bytes = container.ToBytes();

            var parsed = MessageFactory.ParseTangoMessage<Job>(bytes);

            LogManager.Log("Read Message:" + Environment.NewLine + JsonConvert.SerializeObject(parsed.Message, Formatting.Indented));

            Assert.AreEqual(container.Message, parsed.Message);

            LogManager.Log("Test Passed!");

            console.WaitForConsoleExit().Wait();
        }

        /// <summary>
        /// Calls a C++ native library using protobuf and gets a result.
        /// </summary>
        [TestMethod]
        public void Call_CPP_And_Get_Result()
        {
            CalculateRequest request = new CalculateRequest();
            request.A = 10;
            request.B = 5;

            NativePMR<CalculateRequest, CalculateResponse> nativePMR = new NativePMR<CalculateRequest, CalculateResponse>(CalculateCPP);
            CalculateResponse response = nativePMR.Invoke(request);

            Assert.AreEqual(response.Sum, request.A + request.B);
        }

        /// <summary>
        /// Calls a C++ native library using protobuf and gets a result.
        /// </summary>
        [TestMethod]
        public void Call_C_And_Get_Result()
        {
            CalculateRequest request = new CalculateRequest();
            request.A = 10;
            request.B = 5;

            NativePMR<CalculateRequest, CalculateResponse> nativePMR = new NativePMR<CalculateRequest, CalculateResponse>(CalculateC);
            CalculateResponse response = nativePMR.Invoke(request);

            Assert.AreEqual(response.Sum, request.A + request.B);
        }
    }
}