Beispiel #1
0
 public CasterService(CasterSettings settings, IDictionary <string, ILocalServer> servers) : this(settings)
 {
     foreach (KeyValuePair <string, ILocalServer> server in servers)
     {
         NtripClientContext piksi = new NtripClientContext(server.Value, GetMountPoint(server.Key));
         piksi.ClientType = ClientType.NTRIP_ServerLocal;
         _clients.Add(piksi);
     }
 }
Beispiel #2
0
        public CasterService(CasterSettings settings)
        {
            _tcpListener    = new TcpListener(IPAddress.Any, settings.PortNumber);
            _casterPassword = settings.ServerPassword;

            int i = 0;

            foreach (NTRIPMountPoint mountPoint in settings.NTRIPMountPoints)
            {
                _mountPoints.Add(i, new MountPoint(mountPoint.Name, mountPoint.Format, mountPoint.Format, mountPoint.Carrier, mountPoint.NavSystem, mountPoint.Latitude, mountPoint.Longitude));
                i++;
            }

            foreach (NTRIPUser user in settings.NTRIPUsers)
            {
                _users.Add(new KeyValuePair <string, string>(user.UserName, user.UserPassword));
            }


            foreach (LocalServer localServer in settings.LocalServers)
            {
                if (!File.Exists(localServer.DLLPath))
                {
                    throw new FileNotFoundException("Couldn't find dll", localServer.DLLPath);
                }

                Assembly serverAssembly = Assembly.LoadFile(localServer.DLLPath);
                Type     serverType     = serverAssembly.GetType(localServer.ClassName);
                if (serverType == null)
                {
                    throw new NullReferenceException(String.Format("ClassName: {0} doesn't exist in {1}", localServer.ClassName, localServer.DLLPath));
                }
                else if (!CheckILocalServer(serverType))
                {
                    throw new Exception(String.Format("Class: {0} doesn't implement ILocalServer", serverType.Name));
                }

                ILocalServer serverInstance = null;

                foreach (ConstructorInfo constructor in serverType.GetConstructors())
                {
                    ParameterInfo[] parameter = constructor.GetParameters();
                    if (parameter.Length > 0)
                    {
                        if (parameter[0].ParameterType == typeof(String))
                        {
                            serverInstance = (ILocalServer)Activator.CreateInstance(serverType, localServer.ConstructorArguments);
                        }
                    }
                }

                //If type doesn't contain constructor with arguments create it using no parameters
                if (serverInstance == null)
                {
                    serverInstance = (ILocalServer)Activator.CreateInstance(serverType);
                }

                NtripClientContext piksi = new NtripClientContext(serverInstance, GetMountPoint(localServer.MountPoint));
                piksi.ClientType = ClientType.NTRIP_ServerLocal;
                _clients.Add(piksi);
            }
        }