ToggleActive() public method

public ToggleActive ( ) : void
return void
Esempio n. 1
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();
                server.RegisterMediaServer(fileServer);
                state = State.Running;
            }
            catch (Exception ex) {
                server.ErrorFormat("Failed to start {0}, {1}", Description.Name, ex);
                Description.ToggleActive();
                state = State.Stopped;
            }
        }
Esempio n. 2
0
        private void StartFileServer()
        {
            if (!Description.Active)
            {
                InternalState = State.Stopped;
                return;
            }
            var start = DateTime.Now;

            try
            {
                InternalState = 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) => { InternalState = State.Refreshing; };
                fileServer.Changed  += (o, e) => { InternalState = 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);
                InternalState = State.Running;
                var elapsed = DateTime.Now - start;
                LogManager.GetLogger("State").Logger.Log(
                    GetType(),
                    Level.Notice,
                    $"{fileServer.FriendlyName} loaded in {elapsed.TotalSeconds:F2} seconds",
                    null
                    );
            }
            catch (Exception ex)
            {
                server.ErrorFormat("Failed to start {0}, {1}", Description.Name, ex);
                Description.ToggleActive();
                InternalState = State.Stopped;
            }
        }