private void saveBtn_Click(object sender, EventArgs e) { var selectedDevice = (DeviceModel)(allDevicesCb.SelectedItem); var storageModel = (DataStorageConfigModel)fileTypeSelectionCb.SelectedItem; var operatorModel = (OperatorModel)operatorsCb.SelectedItem; var facilityModel = (FacilityModel)facilitiesCb.SelectedItem; var activeChannels = GetActiveChannels(); var configBox = (IDeviceConfigControl)deviceSettingsContainer.Controls[0]; var devConfig = configBox.GetDeviceConfig(); if (devConfig != null && selectedDevice != null && storageModel != null) { this.DialogResult = DialogResult.OK; currentDevice = DeviceFactory.CreateDevice(selectedDevice); var devInterface = PeripheralFactory.CreatePeripheral(devConfig); var dataWriter = DataWriterFactory.CreateDataWriter(fileNameTb.Text, storageModel.Type); var errorHandler = new FileErrorHandler("application_errors.txt"); dataWriter.create(); dataWriter.open(); dataWriter.writeHeader(activeChannels, operatorModel, facilityModel); dataWriter.close(); currentDevice.SetDataWriter(dataWriter); currentDevice.SetPeripheralInterface(devInterface); currentDevice.SetErrorHandler(errorHandler); this.Close(); } }
public void FindMethodsTest() { IDevice device = PeripheralFactory.GetInstance("RandomDevice"); int nbMethodRandomDevice = 4; HashSet <MethodInfo> methodList = PeripheralFactory.FindMethods(device.GetType()); Assert.All(methodList, x => Assert.NotNull(x)); Assert.Equal(nbMethodRandomDevice, methodList.Count); Assert.All(methodList, x => Assert.NotNull(x)); Assert.Collection(methodList, x => Assert.Equal("PeripheralTools.IPeripheralEventHandler get_eventHandler()", x.ToString()), x => Assert.Equal("Void set_eventHandler(PeripheralTools.IPeripheralEventHandler)", x.ToString()), x => Assert.Equal("Void Start()", x.ToString()), x => Assert.Equal("Void Stop()", x.ToString())); device = PeripheralFactory.GetInstance("DeviceWithMethodParameter"); methodList = PeripheralFactory.FindMethods(device.GetType()); nbMethodRandomDevice = 6; Assert.Equal(nbMethodRandomDevice, methodList.Count); Assert.All(methodList, x => Assert.NotNull(x)); List <string> list = methodList.Select(s => s.ToString()).ToList(); Assert.Contains("Void MethodWithParameters(System.String)", list); Assert.Contains("Void MethodWithTwoParameters(System.String, System.String)", list); }
/// <summary> /// Method that calls the method on the right peripheral instance /// </summary> /// <param name="objectName"> Type of the peripheral</param> /// <param name="methodName"> Name of the method to call on the peripheral </param> /// <param name="methodParams"> Array that contains all the parameters value (can be empty) </param> private void UseMethod(string objectName, string methodName, object[] methodParams) { // Getting the peripheral instance based on its name IDevice device = PeripheralFactory.GetInstance(objectName); // Getting all the methods of the device HashSet <MethodInfo> methodList = PeripheralFactory.FindMethods(device.GetType()); MethodInfo correctMethodName = null; // Retreiving the methodInfo which correspond to the "methodName" parameter foreach (MethodInfo method in methodList) { if (method.Name.Equals(methodName)) { correctMethodName = method; } } // Handling a non existing methodName if (correctMethodName is null) { throw new UncorrectMethodNameException(); } // Calling the method with the parameters correctMethodName.Invoke(device, methodParams); }
public void HasConstructorParametersWellSet() { RandomDeviceWithParameters dev = (RandomDeviceWithParameters)PeripheralFactory.GetInstance("RandomDeviceWithParameters"); Assert.Equal("stringTest", dev.stringTest); Assert.Equal(7357, dev.intTest); Assert.True(dev.boolTest); }
public Controller() { computers = new List <IComputer>(); components = new List <IComponent>(); peripherals = new List <IPeripheral>(); computerFactory = new ComputerFactory(); componentFactory = new ComponentFactory(); peripheralFactory = new PeripheralFactory(); }
public void CreateObject() { foreach (string libraryName in reader.GetAllDllName()) { foreach (string instanceName in reader.GetAllInstancesFromOneDll(libraryName)) { Assert.NotNull(PeripheralFactory.GetInstance(instanceName)); } } Assert.Throws <InexistantObjectException>(() => PeripheralFactory.GetInstance("DeviceWithAnErrorInHisName")); }
public void TestEveryInstanceName() { Assert.All(PeripheralFactory.GetAllInstanceNames(), x => Assert.NotNull(x)); Assert.Collection(PeripheralFactory.GetAllInstanceNames(), item => Assert.Equal("RandomDevice", item.ToString()), item => Assert.Equal("RandomDeviceWithParameters", item.ToString()), item => Assert.Equal("DeviceWithMethodParameter", item.ToString())); foreach (string libraryName in reader.GetAllDllName()) { foreach (string instanceName in reader.GetAllInstancesFromOneDll(libraryName)) { Assert.Contains <string>(instanceName, PeripheralFactory.GetAllInstanceNames()); } } }
public void InstanceNumber() { int counter = 0; foreach (string libraryName in reader.GetAllDllName()) { foreach (string instanceName in reader.GetAllInstancesFromOneDll(libraryName)) { ++counter; } } int nbInstance = PeripheralFactory.GetAllInstanceNames().Count; Assert.Equal(counter, nbInstance); }
// // /// <summary> /// Generate every possible path since swagger can't do it dynamically /// </summary> /// <returns> A list of every methods</returns> private List <MethodData> generateAllMethodInfos() { List <MethodData> methodInfosList = new List <MethodData>(); IList <string> peripheralNames = PeripheralFactory.GetAllInstanceNames(); foreach (string currentPeripheralInstanceName in peripheralNames) { IDevice currentPeripheralInstance = PeripheralFactory.GetInstance(currentPeripheralInstanceName); HashSet <MethodInfo> methodList = PeripheralFactory.FindMethods(currentPeripheralInstance.GetType()); foreach (MethodInfo currentMethod in methodList) { if (currentMethod.Name.StartsWith("get_") || currentMethod.Name.StartsWith("set_")) { continue; } string currentRoute = API_START_PATH + currentPeripheralInstanceName + API_END_PATH; currentRoute += currentMethod.Name; ParameterInfo[] currentMethodParameters = currentMethod.GetParameters(); List <OpenApiParameter> parametersList = new List <OpenApiParameter>(); foreach (ParameterInfo currentParameterInfo in currentMethodParameters) { OpenApiParameter currentParameter = new OpenApiParameter { Name = currentParameterInfo.Name, Description = "" + currentParameterInfo.ParameterType, In = ParameterLocation.Query }; parametersList.Add(currentParameter); } MethodData currentMethodData = new MethodData(currentRoute, parametersList); methodInfosList.Add(currentMethodData); } } return(methodInfosList); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseHttpsRedirection(); app.UseRouting(); // Websocket initialisation and handling var webSocketOptions = new WebSocketOptions() { KeepAliveInterval = TimeSpan.FromSeconds(10), ReceiveBufferSize = 4 * 1024 }; app.UseWebSockets(webSocketOptions); app.UseDefaultFiles(); app.UseStaticFiles(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=CommunicateToPeripheral}/{id?}"); }); app.Use(async(context, next) => { // Wait for request on the Specified WS url if (context.Request.Path == WEBSOCKET_URL) { // Check if the request is a websocket one (and not HTTP for instance) if (context.WebSockets.IsWebSocketRequest) { WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(); TaskCompletionSource <object> socketFinishedTcs = new TaskCompletionSource <object>(); SocketHandler socketHandler = new SocketHandler(webSocket, socketFinishedTcs); PeripheralFactory.SetHandler(new PeripheralEventHandler(socketHandler)); await socketFinishedTcs.Task; } else { context.Response.StatusCode = 400; } } else { await next(); } }); app.UseSwagger(); app.UseSwaggerUI(swaggerUiOption => { swaggerUiOption.SwaggerEndpoint("/swagger/v1/swagger.json", "API Test Microservice IPM France"); }); }
public void SetUp() { _factory = new PeripheralFactory(); }
public void HasEventHandlerTest() { Assert.All(PeripheralFactory.GetAllInstanceNames(), x => Assert.NotNull(PeripheralFactory.GetInstance(x).eventHandler)); }
//Init factory for test (with the specified config file) private void InitFactoryForTest() { PeripheralFactory.CONFIGURATION_FILE_PATH = "../../../configFileTest.xml"; PeripheralFactory.Init(); }
public static void Main(string[] args) { PeripheralFactory.Init(); CreateHostBuilder(args).Build().Run(); }