コード例 #1
0
ファイル: Program.cs プロジェクト: marinehero/microserver
        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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: marinehero/microserver
        private void TimerTick_Startup(Gadgeteer.Timer timer)
        {
            //INITIALIZING : SD Storage
            Debug.Print("CobraII: Initializing memory card storage...");

            if (Mainboard.IsSDCardInserted && Mainboard.IsSDCardMounted)
            {
                StorageDevice sd = Mainboard.SDCardStorageDevice;

                if (sd.Volume.IsFormatted)
                {
                    Server = new ServiceManager(LogType.Output, LogLevel.Debug, sd.RootDirectory);
                }
            }
            else
            {
                Server = new ServiceManager(LogType.Output, LogLevel.Debug, null);
            }

            //INITIALIZING : Wireless
            Debug.Print("CobraII: Initializing wireless network...");

            if (!netWifi.Opened)
                netWifi.Open();

            WiFiRS9110.NetworkParameters wifiParms = new WiFiRS9110.NetworkParameters();
            wifiParms.NetworkType = WiFiRS9110.NetworkType.AdHoc;
            wifiParms.SecurityMode = WiFiRS9110.SecurityMode.Open;
            wifiParms.Ssid = "cobra";
            wifiParms.Key = "";                //GetWepBytes("1234567890");  // must be 10 or 26 digits
            wifiParms.Channel = 6;
            netWifi.StartAdHocNetwork(wifiParms);
            Debug.Print("CobraII: Started AdHoc Network: SSID=" + wifiParms.Ssid);

            netWifi.EnableStaticIP("192.168.50.1", "255.255.255.0", "192.168.50.1");
            netWifi.EnableStaticDns(new string[] { "192.168.50.1" });

            if (!netWifi.LinkConnected)
            {
                while (netWifi.NetworkInterface.IPAddress == "0.0.0.0")
                {
                    Debug.Print("CobraII: Waiting for DHCP...");
                    Thread.Sleep(1000);
                }
            }
            //INITIALIZING : MicroServer
            InitMicroServer();
        }
コード例 #3
0
        public void StartAll()
        {
            _service = this;

            // DHCP Service
            if (_dhcpEnabled == true)
            {
                _dhcpService.InterfaceAddress = _interfaceAddress;
                _dhcpService.ServerName = _serverName;
                _dhcpService.DnsSuffix = _dnsSuffix;
                _dhcpService.StorageRoot = _storageRoot;

                if (_sntpEnabled == true)
                {
                    _dhcpService.RemoveOption(DhcpOption.NTPServer);
                    _dhcpService.AddOption(DhcpOption.NTPServer, _interfaceAddress.GetAddressBytes());
                }
                _dhcpService.Start();
            }

            // DNS Service
            if (_dnsEnabled == true)
            {
                _dnsService.InterfaceAddress = _interfaceAddress;
                _dnsService.ServerName = _serverName;
                _dnsService.DnsSuffix = _dnsSuffix;

                if (!StringUtility.IsNullOrEmpty(_serverName) || !StringUtility.IsNullOrEmpty(_dnsSuffix))
                {
                    Answer record = new Answer();
                    record.Domain = string.Concat(_serverName, ".", _dnsSuffix);
                    record.Class = RecordClass.IN;
                    record.Type = RecordType.A;
                    record.Ttl = 60;
                    record.Record = new ARecord(_interfaceAddress.GetAddressBytes());

                    _service.DnsService.ZoneFile.Add(record);

                    Logger.WriteInfo(this, "Device registered with dns:  " + record.Domain);
                }

                _dnsService.Start();
            }

            // SNTP Service
            if (_sntpEnabled == true)
            {
                _sntpService.InterfaceAddress = _interfaceAddress;
                _sntpService.Start();
            }

            // HTTP Service
            if (_httpEnabled == true)
            {
                ModuleManager _moduleManager = new ModuleManager();

                // Add the router module as the fist module to pipeline
                _moduleManager.Add(new RouterModule());

                if (StorageRoot != null)
                {
                    // Create disk file service for the root storage
                    DiskFileService fileService = new DiskFileService("/", StorageRoot + @"\"+ MicroServer.Net.Http.Constants.HTTP_WEB_ROOT_FOLDER + @"\");

                    // Add the file module to pipeline
                    _moduleManager.Add(new FileModule(fileService) { AllowListing = _allowListing });
                }

                // Add the controller module to pipeline
                _moduleManager.Add(new ControllerModule());

                // Add the error module as the last module to pipeline
                _moduleManager.Add(new ErrorModule());

                //  Create the Http service
                _httpService = new HttpService(_moduleManager);

                _httpService.InterfaceAddress = _interfaceAddress;
                _httpService.Start();
            }

            Logger.WriteInfo(this, "Service Manager started all services");
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: marinehero/microserver
        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();
            }
        }