Example #1
0
        // The disk file service allows you to serve and browse files from flash/disk storage
        public static void Main()
        {
            // Initialize logging
            Logger.Initialize(new DebugLogger(), LoggerLevel.Debug);

            // Create Http server pipeline
            ModuleManager ModuleManager = new ModuleManager();

            // Create file/disk service for storage
            DiskFileService fileService = new DiskFileService(@"/", @"\WINFS\WebSite");

            // Add the file module to pipeline and enable the file listing feature
            ModuleManager.Add(new FileModule(fileService) { AllowListing = true });

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

            //  Create the http server
            HttpService HttpServer = new HttpService(ModuleManager);

            // Sets interface ip address
            HttpServer.InterfaceAddress = IPAddress.GetDefaultLocalAddress();

            // Starts Http service
            HttpServer.Start();

            // Set local time
            SntpClient TimeService = new SntpClient();
            TimeService.Synchronize();
        }
Example #2
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");
        }