/// <summary> /// https://msdn.microsoft.com/en-us/library/hh205277(v=vs.110).aspx /// </summary> /// <param name="config"></param> public static void Configure(ServiceConfiguration config) { { config.LoadFromConfiguration(ConfigurationManager.OpenMappedExeConfiguration(new ExeConfigurationFileMap { ExeConfigFilename = @"C:\Atento\03-GeneratedProjects\Atento.Suite.Shared.Application.WcfService\App.config" }, ConfigurationUserLevel.None)); ApplicationLayer.ContainerInit(); SharedRepositoryLayer.IocRegistry(); } }
static void DNP3Response(LinkLayer ll, TransportLayer tl, ApplicationLayer al, ref byte[] buffer) { var appData = ApplicationLayer.ApplicationResponse(al); al.ApplicationData = appData; var transData = TransportLayer.TransportResponse(tl, al); tl.TransportData = transData; var linkData = LinkLayer.LinkResponse(ll, tl); buffer = linkData; }
public static void Main() { // write your code here LinkLayer ll = new LinkLayer(); NetworkLayer network = new NetworkLayer(1, ll); ApplicationLayer app = new ApplicationLayer(network); ll.NewMessageReceived += BlinkLed; _device = new LocalDevice(999, app, "Netduino", "Netduino"); ll.Start(); }
public void Create_ShouldCreateProjectWithCorrectNameInSrcFolder() { var dotnetCliMock = new Mock <IDotNetClient>(); dotnetCliMock.Setup(x => x.CreateClassLibProject(It.IsAny <string>(), It.IsAny <string>())); var domainLayer = new ApplicationLayer(dotnetCliMock.Object); var testFolder = "test"; var projectName = "FooProject"; var expectedFolder = $"{testFolder}/src"; var expectedName = $"{projectName}.Application"; domainLayer.Create(testFolder, projectName); dotnetCliMock.Verify(x => x.CreateClassLibProject(expectedFolder, expectedName), Times.Once); }
/// <summary> /// Load your modules or register your services here! /// </summary> /// <param name="kernel">The kernel.</param> private static void RegisterServices(IKernel kernel) { RepositoryLayer.Register(kernel); ApplicationLayer.Register(kernel); }
/// <summary> /// This is the main function for the simple client. It parses the command line and creates /// a socket of the requested type. For TCP, it will resolve the name and attempt to connect /// to each resolved address until a successful connection is made. Once connected a request /// message is sent followed by shutting down the send connection. The client then receives /// data until the server closes its side at which point the client socket is closed. For /// UDP, the socket is created and if indicated connected to the server's address. A single /// request datagram message. The client then waits to receive a response and continues to /// do so until a zero byte datagram is receive which indicates the end of the response. /// </summary> /// <param name="args">Command line arguments</param> static void Main(string[] args) { SocketType sockType = SocketType.Stream; ProtocolType sockProtocol = ProtocolType.Tcp; string remoteName = "localhost"; bool udpConnect = false; int remotePort = 5150, bufferSize = 4096; Console.WriteLine(); usage(); Console.WriteLine(); // Parse the command line for (int i = 0; i < args.Length; i++) { try { if ((args[i][0] == '-') || (args[i][0] == '/')) { switch (Char.ToLower(args[i][1])) { case 'c': // "Connect" the UDP socket to the destination udpConnect = true; break; case 'n': // Destination address to connect to or send to remoteName = args[++i]; break; case 'p': // Port number for the destination remotePort = System.Convert.ToInt32(args[++i]); break; case 't': // Specified TCP or UDP i++; if (String.Compare(args[i], "tcp", true) == 0) { sockType = SocketType.Stream; sockProtocol = ProtocolType.Tcp; } else if (String.Compare(args[i], "udp", true) == 0) { sockType = SocketType.Dgram; sockProtocol = ProtocolType.Udp; } else { usage(); return; } break; case 'x': // Size of the send and receive buffers bufferSize = System.Convert.ToInt32(args[++i]); break; default: usage(); return; } } } catch { usage(); return; } } Socket clientSocket = null; IPHostEntry resolvedHost = null; IPEndPoint destination = null; byte[] sendBuffer = new byte[bufferSize], recvBuffer = new Byte[bufferSize]; int rc; // Format the string message into the send buffer // we will send the DNP3 request ApplicationLayer al = new ApplicationLayer(); al.ApplicationData = new byte[] { 0x02, 0x00, 0x06 }; al.FunctionCode = (byte)FunctionCode.READ; // Read al.ApplicationControl = 0xc2; al.serialize(ref al.ApplicationData); TransportLayer tl = new TransportLayer(); tl.TransportData = al.ApplicationData; tl.seq = 1; tl.FIN = 1; tl.FIR = 1; tl.serialize(ref tl.TransportData); LinkLayer ll = new LinkLayer(); ll.LinkData = tl.TransportData; ll.source = 3; ll.destination = 4; ll.dir = (byte)DIR.MASTER; ll.prm = (byte)PRM.INITIATED; ll.fcb = (byte)FCB.set; ll.fcv = (byte)FCV.set; ll.functionCode = (byte)PrimaryFunctionCode.PRI_CONFIRMED_USER_DATA; ll.controlByte = ll.GetControlByte(true); ll.serialize(ref ll.LinkData); var sb = new StringBuilder("new byte[] { "); for (var i = 0; i < ll.LinkData.Length; i++) { var b = ll.LinkData[i]; sb.Append(b); if (i < ll.LinkData.Length - 1) { sb.Append(", "); } } sb.Append(" }"); Console.WriteLine("DNP3 data using String Builder " + sb.ToString()); //FormatBuffer(sendBuffer, textMessage); BufferFormatting(ref sendBuffer, ll.LinkData); try { // Try to resolve the remote host name or address resolvedHost = Dns.GetHostEntry(remoteName); Console.WriteLine("Client: GetHostEntry() is OK..."); // Try each address returned foreach (IPAddress addr in resolvedHost.AddressList) { // Create a socket corresponding to the address family of the resolved address clientSocket = new Socket( addr.AddressFamily, sockType, sockProtocol ); Console.WriteLine("Client: Socket() is OK..."); try { // Create the endpoint that describes the destination destination = new IPEndPoint(addr, remotePort); Console.WriteLine("Client: IPEndPoint() is OK. IP Address: {0}, server port: {1}", addr, remotePort); if ((sockProtocol == ProtocolType.Udp) && (udpConnect == false)) { Console.WriteLine("Client: Destination address is: {0}", destination.ToString()); break; } else { Console.WriteLine("Client: Attempting connection to: {0}", destination.ToString()); } clientSocket.Connect(destination); Console.WriteLine("Client: Connect() is OK..."); break; } catch (SocketException) { // Connect failed, so close the socket and try the next address clientSocket.Close(); Console.WriteLine("Client: Close() is OK..."); clientSocket = null; continue; } } // Make sure we have a valid socket before trying to use it if ((clientSocket != null) && (destination != null)) { try { new Thread(() => { int sendCount = 0; while (true && sendCount < 1) { // Send the request to the server if ((sockProtocol == ProtocolType.Udp) && (udpConnect == false)) { clientSocket.SendTo(sendBuffer, destination); sendCount++; Console.WriteLine("Client: SendTo() is OK...UDP..."); } else { rc = clientSocket.Send(sendBuffer); sendCount++; Console.WriteLine("Client: send() is OK...TCP..."); Console.WriteLine("Client: Sent request of {0} bytes", rc); // For TCP, shutdown sending on our side since the client won't send any more data if (sockProtocol == ProtocolType.Tcp) { //clientSocket.Shutdown(SocketShutdown.Send); //Console.WriteLine("Client: Shutdown() is OK..."); } } } }).Start(); // Receive data in a loop until the server closes the connection. For // TCP this occurs when the server performs a shutdown or closes // the socket. For UDP, we'll know to exit when the remote host // sends a zero byte datagram. new Thread(() => { while (true) { if ((sockProtocol == ProtocolType.Tcp) || (udpConnect == true)) { rc = clientSocket.Receive(recvBuffer); Console.WriteLine("Client: Receive() is OK..."); Console.WriteLine("Client: Read {0} bytes", rc); recvBuffer = recvBuffer.Where((v, i) => i < rc).ToArray(); var sbs = new StringBuilder("new byte[] { "); for (var i = 0; i < recvBuffer.Length; i++) { var b = recvBuffer[i]; sbs.Append(b); if (i < recvBuffer.Length - 1) { sbs.Append(", "); } } sbs.Append(" }"); Console.WriteLine("DNP3 Application response " + sbs.ToString()); } else { IPEndPoint fromEndPoint = new IPEndPoint(destination.Address, 0); Console.WriteLine("Client: IPEndPoint() is OK..."); EndPoint castFromEndPoint = (EndPoint)fromEndPoint; rc = clientSocket.ReceiveFrom(recvBuffer, ref castFromEndPoint); Console.WriteLine("Client: ReceiveFrom() is OK..."); fromEndPoint = (IPEndPoint)castFromEndPoint; Console.WriteLine("Client: Read {0} bytes from {1}", rc, fromEndPoint.ToString()); } // Exit loop if server indicates shutdown if (rc == 0) { clientSocket.Close(); Console.WriteLine("Client: Close() is OK..."); break; } } }).Start(); } catch (SocketException err) { Console.WriteLine("Client: Error occurred while sending or receiving data."); Console.WriteLine(" Error: {0}", err.Message); } } else { Console.WriteLine("Client: Unable to establish connection to server!"); } } catch (SocketException err) { Console.WriteLine("Client: Socket error occurred: {0}", err.Message); } }