Ejemplo n.º 1
0
        private static void OnConfigChange(object sender, FileSystemEventArgs e)
        {
            if (counter == 0)
            {
                counter++;
                return;
            }

            counter = 0;
            try
            {
                logWriter?.Dispose();
                logStream?.Dispose();
                Listener.Config = Config.ParseConfig(out logStream, out logWriter);
            }
            catch (Exception ex)
            {
                Log(new ApiLogMessage($"Failed to de-serialize config, using current config instead. Exception: {ex.Message}{Environment.NewLine}{ex.StackTrace}", ApiLogLevel.Warning));
            }
            Listener.Stop();
            Listener.Start();
            try
            {
                MetadataStore.LoadMetadata(Log);
            }
            catch (Exception ex)
            {
                Log(new ApiLogMessage($"Failed to load metadata. Exception: {ex.Message}{Environment.NewLine}{ex.StackTrace}", ApiLogLevel.Critical));
            }
        }
Ejemplo n.º 2
0
        private void OnConfigChange(object sender, FileSystemEventArgs e)
        {
            if (counter == 0)
            {
                counter++;
                return;
            }

            counter = 0;
            Listener.Stop();
            try
            {
                logWriter?.Dispose();
                logStream?.Dispose();
                Listener.Config = Config.ParseConfig(out logStream, out logWriter);
            }
            catch
            { }
            Listener.Start();
            try
            {
                MetadataStore.LoadMetadata();
            }
            catch (Exception ex)
            {
                if (logStream != null)
                {
                    logWriter?.WriteLine(
                        $"{Enum.GetName(typeof(ApiLogLevel), ApiLogLevel.Critical)?.ToUpper()}: Failed to load metadata. Exception: {ex.Message}{Environment.NewLine}{ex.StackTrace}");
                    logWriter?.Flush();
                }
            }
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var monitor = new object();

            try
            {
                Listener.Config = Config.ParseConfig(out logStream, out logWriter);
            }
            catch (Exception e)
            {
                Log(new ApiLogMessage($"Failed to de-serialize config, using default config instead. Exception: {e.Message}{Environment.NewLine}{e.StackTrace}", ApiLogLevel.Warning));
                Listener.Config = Config.DefaultConfig;
            }

            if ((args.Length == 1 || args.Length == 2) && args[0].ToLowerInvariant().Trim() == "verify")
            {
                bool showUnused = args.Length == 2 && args[1].ToLowerInvariant().Trim() == "--showunused";
                bool result     = MetadataStore.VerifyMetadata(showUnused, Log);
                if (result)
                {
                    Log(new ApiLogMessage("No errors.", ApiLogLevel.Info));
                }
                return;
            }

            try
            {
                MetadataStore.LoadMetadata(Log);
            }
            catch (Exception e)
            {
                Log(new ApiLogMessage($"Failed to load metadata. Exception: {e.Message}{Environment.NewLine}{e.StackTrace}", ApiLogLevel.Critical));
                return;
            }

            watcher = new FileSystemWatcher(Environment.CurrentDirectory, "MusicCatConfig.json")
            {
                NotifyFilter = NotifyFilters.LastWrite
            };
            watcher.Changed            += OnConfigChange;
            watcher.EnableRaisingEvents = true;

            Listener.AttachLogger(Log);
            Console.CancelKeyPress += (sender, cancelArgs) => Monitor.Pulse(monitor);
            Listener.Start();
            lock (monitor)
            {
                Monitor.Wait(monitor);
            }
            logWriter?.Dispose();
            logStream?.Dispose();
            Listener.Stop();
        }
Ejemplo n.º 4
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Listener.Config = Config.ParseConfig(out logStream, out logWriter);
            }
            catch
            {
                Listener.Config = Config.DefaultConfig;
            }

            try
            {
                MetadataStore.LoadMetadata();
            }
            catch (Exception e)
            {
                if (logStream != null)
                {
                    logWriter?.WriteLine(
                        $"{Enum.GetName(typeof(ApiLogLevel), ApiLogLevel.Critical)?.ToUpper()}: Failed to load metadata. Exception: {e.Message}{Environment.NewLine}{e.StackTrace}");
                    logWriter?.Flush();
                }
                Environment.Exit(1);
            }

            Listener.AttachLogger(m =>
            {
                if (m.Level >= displayLogLevel)
                {
                    if (logStream != null)
                    {
                        logWriter?.WriteLine($"{Enum.GetName(typeof(ApiLogLevel), m.Level)?.ToUpper()}: {m.Message}");
                        logWriter?.Flush();
                    }
                }
            });

            watcher = new FileSystemWatcher(Environment.CurrentDirectory, "MusicCatConfig.json")
            {
                NotifyFilter = NotifyFilters.LastWrite
            };
            watcher.Changed            += OnConfigChange;
            watcher.EnableRaisingEvents = true;

            Listener.Start();
        }
Ejemplo n.º 5
0
        protected override void OnStart(string[] args)
        {
            try
            {
                Listener.Config = Config.ParseConfig(out logStream, out logWriter);
            }
            catch
            {
                Listener.Config = Config.DefaultConfig;
            }

            try
            {
                MetadataStore.LoadMetadata();
            }
            catch (Exception e)
            {
                if (logStream != null)
                {
                    logWriter?.WriteLine(
                        $"{Enum.GetName(typeof(ApiLogLevel), ApiLogLevel.Critical)?.ToUpper()}: Failed to load metadata. Exception: {e.Message}{Environment.NewLine}{e.StackTrace}");
                    logWriter?.Flush();
                }
                Environment.Exit(1);
            }

            Listener.AttachLogger(m =>
            {
                if (m.Level >= displayLogLevel)
                {
                    if (logStream != null)
                    {
                        logWriter?.WriteLine($"{Enum.GetName(typeof(ApiLogLevel), m.Level)?.ToUpper()}: {m.Message}");
                        logWriter?.Flush();
                    }
                }
            });
            Listener.Start();
        }