Example #1
0
        public static void Main()
        {
            Server = new ServiceManager(LogType.Output, LogLevel.Debug, @"\winfs");

            //INITIALIZING : Server Services
            Server.InterfaceAddress = System.Net.IPAddress.GetDefaultLocalAddress().ToString();
            Server.ServerName = "example";
            Server.DnsSuffix = "iot.local";

            // SERVICES:  Enable / disable additional services
            Server.DhcpEnabled = false;
            Server.DnsEnabled = true;
            Server.SntpEnabled = true;

            //SERVICE:  Enable / disable directory browsing
            Server.AllowListing = false;

            //SERVICE: DHCP
            Server.DhcpService.PoolRange("172.16.10.100", "172.16.10.254");
            Server.DhcpService.GatewayAddress = "172.16.10.1";
            Server.DhcpService.SubnetMask = "255.255.255.0";

            //SERVICES: Start all services
            Server.StartAll();

            string url = string.Concat("http://", Server.HttpService.InterfaceAddress, ":", "81");
            Server.LogInfo ("MicroServer.Sample", "Launch Web Browser: " + url);
        }
Example #2
0
        public static void Main()
        {
            using (ServiceManager Server = new ServiceManager(LogType.Output, LogLevel.Info, @"\winfs"))
            {
                Server.LogInfo("MicroServer.Emulator", "Starting service manager main code");

                ConfigManager.Load(Server.StorageRoot + @"\settings.xml");

                // general interface information settings
                //Server.InterfaceAddress = ConfigManager.GetSetting("ipAddress", System.Net.IPAddress.GetDefaultLocalAddress().ToString());
                Server.InterfaceAddress = "192.168.10.8";
                Server.DnsSuffix = ConfigManager.GetSetting("dnsSuffix","iot.local");
                Server.ServerName = ConfigManager.GetSetting("serverName", "mfhost");

                // enable the services you would like to start
                Server.HttpEnabled = true;

                // dhcp server settings
                bool dhcpEnabled;
                if (ParseUtility.TryParseBool(ConfigManager.GetSetting("dhcpEnabled", "false"), out dhcpEnabled))
                {
                    Server.DhcpEnabled = dhcpEnabled;
                    Server.DhcpService.PoolRange(
                        ConfigManager.GetSetting("startAddress", "192.168.50.100"),
                        ConfigManager.GetSetting("endAddress", "192.168.50.254")
                        );
                    //Server.DhcpService.PoolReservation("192.168.10.99", "000C291DBB7D");
                    Server.DhcpService.GatewayAddress = Server.InterfaceAddress;
                    Server.DhcpService.SubnetMask = ConfigManager.GetSetting("subnetMask", "255.255.255.0");
                    Server.DhcpService.NameServers = new NameServerCollection(Server.InterfaceAddress);
                }

                // dns server settings
                bool dnsEnabled;
                if (ParseUtility.TryParseBool(ConfigManager.GetSetting("dnsEnabled", "false"), out dnsEnabled))
                    Server.DnsEnabled = dnsEnabled;

                // sntp server settings
                bool sntpEnabled;
                if (ParseUtility.TryParseBool(ConfigManager.GetSetting("sntpEnabled", "false"), out sntpEnabled))
                    Server.SntpEnabled = sntpEnabled;

                // event handlers for dhcp service
                Server.DhcpService.OnDhcpMessageReceived += DhcpService_OnDhcpMessageReceived;
                Server.DhcpService.OnDhcpMessageSent += DhcpService_OnDhcpMessageSent;
                Server.DhcpService.OnLeaseAcknowledged += DhcpService_OnLeaseAcknowledged;
                Server.DhcpService.OnLeaseDeclined += DhcpService_OnLeaseDeclined;
                Server.DhcpService.OnLeaseReleased += DhcpService_OnLeaseReleased;

                // event handlers for dns service
                Server.DnsService.OnDnsMessageReceived += DnsService_OnDnsMessageReceived;
                Server.DnsService.OnDnsMessageSent += DnsService_OnDnsMessageSent;

                // event handlers for sntp service
                Server.SntpService.OnSntpMessageReceived += SntpService_OnSntpMessageReceived;
                Server.SntpService.OnSntpMessageSent += SntpService_OnSntpMessageSent;

                // start all enabled services
                Server.StartAll();

                Server.LogInfo("MicroServer.Emulator", "Ending service manager main code");
            }

            if (SystemInfo.IsEmulator)
            {
                SntpClient TimeService = new SntpClient();
                TimeService.Synchronize();
            }
        }