상속: Logging, IDisposable
예제 #1
0
 public HttpAuthorizer(HttpServer server)
 {
     if (server == null) {
     throw new ArgumentNullException("server");
       }
       this.server = server;
       server.OnAuthorizeClient += OnAuthorize;
 }
예제 #2
0
        public ServerListViewItem(HttpServer server, FileInfo cacheFile, ServerDescription description)
        {
            this.server = server;
              this.cacheFile = cacheFile;
              Description = description;

              Text = Description.Name;
              SubItems.Add(Description.Directories.Length.ToString());
              ImageIndex = 0;
        }
예제 #3
0
        public HttpClient(HttpServer aOwner, TcpClient aClient)
        {
            State = HttpStates.ACCEPTED;
              lastActivity = DateTime.Now;

              owner = aOwner;
              client = aClient;
              stream = client.GetStream();
              client.Client.UseOnlyOverlappedIO = true;

              RemoteEndpoint = client.Client.RemoteEndPoint as IPEndPoint;
              LocalEndPoint = client.Client.LocalEndPoint as IPEndPoint;
        }
예제 #4
0
    private static void Main(string[] args)
    {
      Console.WriteLine();
      var options = new Options();
      try {
        Console.TreatControlCAsInput = false;
        Console.CancelKeyPress += CancelKeyPressed;

        options.Parse(args);
        if (options.ShowHelp) {
          options.PrintUsage();
          return;
        }
        if (options.ShowVersion) {
          ShowVersion();
          return;
        }
        if (options.ShowLicense) {
          ShowLicense();
          return;
        }
        if (options.ListViews) {
          ListViews();
          return;
        }
        if (options.ListOrders) {
          ListOrders();
          return;
        }
        if (options.Directories.Length == 0) {
          throw new GetOptException("No directories specified");
        }

        options.SetupLogging();

        using (var icon = new ProgramIcon()) {
          var server = new HttpServer(options.Port);
          try {
            using (var authorizer = new HttpAuthorizer(server)) {
              if (options.Ips.Length != 0) {
                authorizer.AddMethod(new IPAddressAuthorizer(options.Ips));
              }
              if (options.Macs.Length != 0) {
                authorizer.AddMethod(new MacAuthorizer(options.Macs));
              }
              if (options.UserAgents.Length != 0) {
                authorizer.AddMethod(
                  new UserAgentAuthorizer(options.UserAgents));
              }

              Console.Title = "SimpleDLNA - starting ...";

              var types = options.Types[0];
              foreach (var t in options.Types) {
                types = types | t;
                server.InfoFormat("Enabled type {0}", t);
              }

              var friendlyName = "sdlna";

              if (options.Seperate) {
                foreach (var d in options.Directories) {
                  server.InfoFormat("Mounting FileServer for {0}", d.FullName);
                  var fs = SetupFileServer(
                    options, types, new DirectoryInfo[] { d });
                  friendlyName = fs.FriendlyName;
                  server.RegisterMediaServer(fs);
                  server.NoticeFormat("{0} mounted", d.FullName);
                }
              }
              else {
                server.InfoFormat(
                  "Mounting FileServer for {0} ({1})",
                  options.Directories[0], options.Directories.Length);
                var fs = SetupFileServer(options, types, options.Directories);
                friendlyName = fs.FriendlyName;
                server.RegisterMediaServer(fs);
                server.NoticeFormat(
                  "{0} ({1}) mounted",
                  options.Directories[0], options.Directories.Length);
              }

              Console.Title = String.Format("{0} - running ...", friendlyName);

              Run(server);
            }
          }
          finally {
            server.Dispose();
          }
        }
      }
      catch (GetOptException ex) {
        Console.Error.WriteLine("Error: {0}\n\n", ex.Message);
        options.PrintUsage();
      }
#if !DEBUG
      catch (Exception ex) {
        LogManager.GetLogger(typeof(Program)).Fatal("Failed to run", ex);
      }
#endif
    }
예제 #5
0
    private static void Run(HttpServer server)
    {
      server.Info("CTRL-C to terminate");
      BlockEvent.WaitOne();

      server.Info("Going down!");
      server.Info("Closed!");
    }
예제 #6
0
        static void Main(string[] args)
        {
            Console.WriteLine();
            var opcoes = new Opcoes();
            try
            {
                Console.TreatControlCAsInput = false;
                Console.CancelKeyPress += CancelKeyPressed;

                opcoes.Parse(args);

                if (opcoes.ListaVisualizacoes)
                {
                    ListaVisualizacoes();
                    return;
                }
                if (opcoes.ListaOrdens)
                {
                    ListaOrdens();
                    return;
                }
                if (opcoes.Diretorios.Length == 0)
                {
                    throw new GetOptException("Nenhum diretório especificado");
                }

                var servidor = new HttpServer(opcoes.Porta);
                try
                {

                    using (var autorizador = new HttpAuthorizer(servidor))
                    {
                        if (opcoes.Ips.Length != 0)
                        {
                            autorizador.AddMethod(new IPAddressAuthorizer(opcoes.Ips));
                        }
                        if (opcoes.Macs.Length != 0)
                        {
                            autorizador.AddMethod(new MacAuthorizer(opcoes.Macs));
                        }
                        if (opcoes.UserAgents.Length != 0)
                        {
                            autorizador.AddMethod(
                              new UserAgentAuthorizer(opcoes.UserAgents));
                        }

                        Console.Title = "dlna";

                        var tipos = opcoes.Tipos[0];
                        foreach (var t in opcoes.Tipos)
                        {
                            tipos = tipos | t;
                            servidor.InfoFormat("Tipos ativado {0}", t);
                        }

                        var friendlyName = "dlna";

                        if (opcoes.Separacao)
                        {
                            foreach (var d in opcoes.Diretorios)
                            {
                                servidor.InfoFormat("Montando Servidor de Midia da pasta {0}", d.FullName);
                                var fs = ConfiguraServidorDeArquivos(
                                  opcoes, tipos, new DirectoryInfo[] { d });
                                friendlyName = fs.FriendlyName;
                                servidor.RegisterMediaServer(fs);
                                servidor.NoticeFormat("{0} montado", d.FullName);
                            }
                        }
                        else
                        {
                            servidor.InfoFormat(
                              "Montando Servidor de Midia da pasta {0} ({1})",
                              opcoes.Diretorios[0], opcoes.Diretorios.Length);
                            var fs = ConfiguraServidorDeArquivos(opcoes, tipos, opcoes.Diretorios);
                            friendlyName = fs.FriendlyName;
                            servidor.RegisterMediaServer(fs);
                            servidor.NoticeFormat(
                              "{0} ({1}) montado",
                              opcoes.Diretorios[0], opcoes.Diretorios.Length);
                        }

                        Console.Title = String.Format("{0} - rodando ...", friendlyName);

                        Rodar(servidor);
                    }
                }
                finally
                {
                    servidor.Dispose();
                }

            }
            catch (GetOptException ex)
            {
                Console.Error.WriteLine("Error: {0}\n\n", ex.Message);
                opcoes.PrintUsage();
            }
        }
예제 #7
0
        private static void Rodar(HttpServer servidor)
        {
            servidor.Info("CTRL-C para terminar");
            BlockEvent.WaitOne();

            servidor.Info("Desligando!");
            servidor.Info("Fechado!");
        }
예제 #8
0
 public IndexHandler(HttpServer owner)
 {
     this.owner = owner;
 }
예제 #9
0
 public IndexHandler(HttpServer owner)
 {
     this.owner = owner;
 }
예제 #10
0
파일: Program.cs 프로젝트: Nirad/simpleDLNA
        private static void Run(HttpServer server)
        {
            BlockEvent.WaitOne();

              server.Info("Going down!");
              server.Info("Closed!");
        }