Exemple #1
0
        public void Init()
        {
            var storePath = _parameters.Keys.Contains("file") ? Convert.ToString(_parameters.GetValuesForKey("file").First()):DefaultFileName;

            if (!Path.IsPathRooted(storePath))
            {
                storePath = DataPath.Combine(storePath);
            }
            _storeFile = new FileInfo(storePath);
            _logger.NoticeFormat("Opening [{0}] Store...", _storeFile);
            _db = RaptorDB <string> .Open(_storeFile.FullName, false);
        }
Exemple #2
0
        public HttpServer(int port)
        {
            prefixes.TryAdd(
                "/favicon.ico",
                new StaticHandler(
                    new ResourceResponse(HttpCode.Ok, "image/icon", "favicon"))
                );
            prefixes.TryAdd(
                "/static/browse.css",
                new StaticHandler(
                    new ResourceResponse(HttpCode.Ok, "text/css", "browse_css"))
                );
            RegisterHandler(new IconHandler());

            listener            = new TcpListener(new IPEndPoint(IPAddress.Any, port));
            listener.Server.Ttl = 32;
            listener.Server.UseOnlyOverlappedIO = true;
            listener.Start();

            RealPort = (listener.LocalEndpoint as IPEndPoint).Port;

            Logger.NoticeFormat(
                "Running HTTP Server: {0} on port {1}", Signature, RealPort);
            ssdpServer = new SsdpHandler();

            timeouter.Elapsed += TimeouterCallback;
            timeouter.Enabled  = true;

            Accept();
        }
Exemple #3
0
 private void OpenConnection(FileInfo storeFile,
                             out IDbConnection newConnection)
 {
     lock (globalLock) {
         newConnection = Sqlite.GetDatabaseConnection(storeFile);
         try {
             using (var ver = newConnection.CreateCommand()) {
                 ver.CommandText = "PRAGMA user_version";
                 var currentVersion = (uint)(long)ver.ExecuteScalar();
                 if (!currentVersion.Equals(SCHEMA))
                 {
                     throw new ArgumentOutOfRangeException("SCHEMA");
                 }
             }
         }
         catch (Exception ex) {
             _logger.NoticeFormat(
                 "Recreating database, schema update. ({0})",
                 ex.Message
                 );
             Sqlite.ClearPool(newConnection);
             newConnection.Close();
             newConnection.Dispose();
             newConnection = null;
             for (var i = 0; i < 10; ++i)
             {
                 try {
                     GC.Collect();
                     storeFile.Delete();
                     break;
                 }
                 catch (IOException) {
                     Thread.Sleep(100);
                 }
             }
             newConnection = Sqlite.GetDatabaseConnection(storeFile);
         }
         using (var pragma = connection.CreateCommand()) {
             pragma.CommandText = "PRAGMA journal_size_limt = 33554432";
             pragma.ExecuteNonQuery();
             pragma.CommandText = "PRAGMA wal_autocheckpoint = 100";
             pragma.ExecuteNonQuery();
             pragma.CommandText = "PRAGMA wal_checkpoint(TRUNCATE)";
             pragma.ExecuteNonQuery();
         }
     }
 }
Exemple #4
0
        public override void SetParameters(AttributeCollection parameters)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            base.SetParameters(parameters);
            if (parameters.Count == 0)
            {
                return;
            }

            var filters = from f in parameters.Keys
                          let e = Escape(f)
                                  select e;

            filter = new Regex(
                String.Join("|", filters),
                RegexOptions.Compiled | RegexOptions.IgnoreCase
                );
            _logger.NoticeFormat("Using filter {0}", filter.ToString());
        }
Exemple #5
0
 public bool Authorize(HttpRequestAuthParameters ap)//IHeaders headers, IPEndPoint endPoint, string mac)
 {
     _logger.NoticeFormat("Authorize:[{0}]", ap);
     if (methods.Count == 0)
     {
         return(true);
     }
     try {
         foreach (var m in methods)
         {
             if (m.Authorize(ap))
             {
                 return(true);
             }
         }
         return(false);
     }
     catch (Exception ex) {
         _logger.Error("Failed to authorize", ex);
         return(false);
     }
 }