コード例 #1
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            if (!Configuration.Dlna.IsEnabled)
            {
                Logger.LogInformation("DLNA service disabled.");
                return;
            }
            var server = new HttpServer(LoggerFactory.CreateLogger("HttpServer"), Configuration.Dlna.Port ?? 0);

            _authorizer = new HttpAuthorizer(server);
            if (Configuration.Dlna.AllowedIps.Any())
            {
                _authorizer.AddMethod(new IPAddressAuthorizer(Configuration.Dlna.AllowedIps));
            }
            if (Configuration.Dlna.AllowedUserAgents.Any())
            {
                _authorizer.AddMethod(new UserAgentAuthorizer(Configuration.Dlna.AllowedUserAgents));
            }
            DbContext = DbContextFactory.Create(Configuration);

            var defaultNotFoundImages = new DefaultNotFoundImages(LoggerFactory.CreateLogger("DefaultNotFoundImages"), Configuration);
            var imageService          = new ImageService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("ImageService"), defaultNotFoundImages);
            var trackService          = new TrackService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("TrackService"));
            var roadieScrobbler       = new RoadieScrobbler(Configuration, LoggerFactory.CreateLogger("RoadieScrobbler"), DbContext, CacheManager);
            var scrobbleHandler       = new ScrobbleHandler(Configuration, LoggerFactory.CreateLogger("ScrobbleHandler"), DbContext, CacheManager, roadieScrobbler);
            var playActivityService   = new PlayActivityService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("PlayActivityService"), scrobbleHandler);

            var rs = new DlnaService(Configuration, DbContext, CacheManager, LoggerFactory.CreateLogger("DlnaService"), imageService, trackService, playActivityService);

            rs.Preload();

            server.RegisterMediaServer(Configuration, LoggerFactory.CreateLogger("MediaMount"), rs);

            while (!cancellationToken.IsCancellationRequested)
            {
                await Task.Delay(5000, cancellationToken);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: jxp/simpleDLNA
        private static void Main(string[] args)
        {
            Console.WriteLine();
            var options = new Options();

            try {
                Console.TreatControlCAsInput = false;
                Console.CancelKeyPress      += CancelKeyPressed;

                options.Parse(args);
                MKVTools.Initialise(options.MKVTools.DirectoryName);
                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 (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[] { 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 = $"{friendlyName} - running ...";

                            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
        }
コード例 #3
0
        private void StartFileServer()
        {
            if (!Description.Active)
            {
                state = State.Stopped;
                return;
            }
            try {
                state = State.Loading;
                var ids = new Identifiers(ComparerRepository.Lookup(Description.Order), Description.OrderDescending);
                foreach (var v in Description.Views)
                {
                    ids.AddView(v);
                }
                var dirs = (from i in Description.Directories
                            let d = new DirectoryInfo(i)
                                    where d.Exists
                                    select d).ToArray();
                if (dirs.Length == 0)
                {
                    throw new InvalidOperationException("No remaining directories");
                }
                fileServer = new FileServer(Description.Types, ids, dirs)
                {
                    FriendlyName = Description.Name
                };
#if !DEBUG
                if (cacheFile != null)
                {
                    fileServer.SetCacheFile(cacheFile);
                }
#endif
                fileServer.Changing += (o, e) =>
                {
                    state = State.Refreshing;
                };
                fileServer.Changed += (o, e) =>
                {
                    state = Description.Active ? State.Running : State.Stopped;
                };
                fileServer.Load();
                var authorizer = new HttpAuthorizer();
                if (Description.Ips.Length != 0)
                {
                    authorizer.AddMethod(new IPAddressAuthorizer(Description.Ips));
                }
                if (Description.Macs.Length != 0)
                {
                    authorizer.AddMethod(new MacAuthorizer(Description.Macs));
                }
                if (Description.UserAgents.Length != 0)
                {
                    authorizer.AddMethod(new UserAgentAuthorizer(Description.UserAgents));
                }
                fileServer.Authorizer = authorizer;
                server.RegisterMediaServer(fileServer);
                state = State.Running;
            }
            catch (Exception ex) {
                server.ErrorFormat("Failed to start {0}, {1}", Description.Name, ex);
                Description.ToggleActive();
                state = State.Stopped;
            }
        }
コード例 #4
0
        private void StartFileServer()
        {
            if (!Description.Active)
            {
                state = State.Stopped;
                return;
            }
            var start = DateTime.Now;

            try {
                state = State.Loading;
                var ids = new Identifiers(ComparerRepository.Lookup(Description.Order), Description.OrderDescending);
                foreach (var v in Description.Views)
                {
                    ids.AddView(v);
                }
                var dirs = (from i in Description.Directories
                            let d = new DirectoryInfo(i)
                                    where d.Exists
                                    select d).ToArray();
                if (dirs.Length == 0)
                {
                    throw new InvalidOperationException("No remaining directories");
                }
                fileServer = new FileServer(Description.Types, ids, dirs)
                {
                    FriendlyName = Description.Name
                };
//#if !DEBUG
                if (!string.IsNullOrEmpty(Description.FileStore))
                {
                    fileServer.SetCacheFile(FileStoreRepository.Lookup(Description.FileStore));
                }
                //if (cacheFile != null) {
                //  fileServer.SetCacheFile();
                //}
//#endif
                fileServer.Changing += (o, e) =>
                {
                    state = State.Refreshing;
                };
                fileServer.Changed += (o, e) =>
                {
                    state = Description.Active ? State.Running : State.Stopped;
                };
                fileServer.Load();
                var authorizer = new HttpAuthorizer();
                if (Description.Ips.Length != 0)
                {
                    authorizer.AddMethod(new IPAddressAuthorizer(Description.Ips));
                }
                if (Description.Macs.Length != 0)
                {
                    authorizer.AddMethod(new MacAuthorizer(Description.Macs));
                }
                if (Description.UserAgents.Length != 0)
                {
                    authorizer.AddMethod(new UserAgentAuthorizer(Description.UserAgents));
                }
                fileServer.Authorizer = authorizer;
                server.RegisterMediaServer(fileServer);
                state = State.Running;
                var elapsed = DateTime.Now - start;
                LogManager.GetLogger("State").Logger.Log(
                    GetType(),
                    Level.Notice,
                    string.Format(
                        "{0} loaded in {1:F2} seconds",
                        fileServer.FriendlyName,
                        elapsed.TotalSeconds),
                    null
                    );
            }
            catch (Exception ex) {
                server.Logger.ErrorFormat("Failed to start {0}, {1}", Description.Name, ex);
                Description.ToggleActive();
                state = State.Stopped;
            }
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: vitska/simpleDLNA
        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.Logger.InfoFormat("Enabled type {0}", t);
              }

              var friendlyName = "sdlna";

              if (options.Seperate) {
                foreach (var d in options.Directories) {
                  server.Logger.InfoFormat("Mounting FileServer for {0}", d.FullName);
                  var fs = SetupFileServer(
                    options, types, new DirectoryInfo[] { d });
                  friendlyName = fs.FriendlyName;
                  server.RegisterMediaServer(fs);
                  server.Logger.NoticeFormat("{0} mounted", d.FullName);
                }
              }
              else {
                server.Logger.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.Logger.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
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: dmusz/simpleDLNA
            protected override void OnStart(string[] args)
            {
                System.Environment.CurrentDirectory = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
                //Program.Start(StartupArgs);
                var options = new Options();

                try
                {
                    options.Parse(StartupArgs);
                    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())
                    {
                        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));
                                }

                                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);
                                }
                            }
                        }
                        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
            }
コード例 #7
0
 private void StartFileServer()
 {
     if (!Description.Active) {
     state = State.Stopped;
     return;
       }
       var start = DateTime.Now;
       try {
     state = State.Loading;
     var ids = new Identifiers(ComparerRepository.Lookup(Description.Order), Description.OrderDescending);
     foreach (var v in Description.Views) {
       ids.AddView(v);
     }
     var dirs = (from i in Description.Directories
             let d = new DirectoryInfo(i)
             where d.Exists
             select d).ToArray();
     if (dirs.Length == 0) {
       throw new InvalidOperationException("No remaining directories");
     }
     fileServer = new FileServer(Description.Types, ids, dirs) {
       FriendlyName = Description.Name
     };
     //#if !DEBUG
     if(!string.IsNullOrEmpty(Description.FileStore)) {
       fileServer.SetCacheFile(FileStoreRepository.Lookup(Description.FileStore));
     }
     //if (cacheFile != null) {
     //  fileServer.SetCacheFile();
     //}
     //#endif
     fileServer.Changing += (o, e) =>
     {
       state = State.Refreshing;
     };
     fileServer.Changed += (o, e) =>
     {
       state = Description.Active ? State.Running : State.Stopped;
     };
     fileServer.Load();
     var authorizer = new HttpAuthorizer();
     if (Description.Ips.Length != 0) {
       authorizer.AddMethod(new IPAddressAuthorizer(Description.Ips));
     }
     if (Description.Macs.Length != 0) {
       authorizer.AddMethod(new MacAuthorizer(Description.Macs));
     }
     if (Description.UserAgents.Length != 0) {
       authorizer.AddMethod(new UserAgentAuthorizer(Description.UserAgents));
     }
     fileServer.Authorizer = authorizer;
     server.RegisterMediaServer(fileServer);
     state = State.Running;
     var elapsed = DateTime.Now - start;
     LogManager.GetLogger("State").Logger.Log(
       GetType(),
       Level.Notice,
       string.Format(
     "{0} loaded in {1:F2} seconds",
     fileServer.FriendlyName,
     elapsed.TotalSeconds),
       null
     );
       }
       catch (Exception ex) {
     server.Logger.ErrorFormat("Failed to start {0}, {1}", Description.Name, ex);
     Description.ToggleActive();
     state = State.Stopped;
       }
 }