コード例 #1
0
ファイル: PluginImport.cs プロジェクト: tobiaswuerth/mux-cli
        protected override void Process(String[] args)
        {
            OnProcessStarting();
            TriggerActions(args.ToList());

            List <String> paths = args.Distinct().Select(x => x.Trim()).ToList();

            if (paths.Count.Equals(0))
            {
                LoggerBundle.Fatal(new ArgumentException("no argument given"));
                Environment.Exit(1);
            }

            foreach (String path in paths)
            {
                LoggerBundle.Inform($"Processing path '{path}'...");
                if (!Directory.Exists(path))
                {
                    LoggerBundle.Warn($"Path '{path}' not found. Skipping.");
                    continue;
                }

                LoggerBundle.Debug("Preloading data...");
                List <String> tracks;
                Stopwatch     sw = new Stopwatch();
                sw.Start();
                using (DataContext dataContext = DataContextFactory.GetInstance())
                {
                    tracks = dataContext.SetTracks.AsNoTracking().Select(x => x.Path).ToList();
                }
                sw.Stop();
                LoggerBundle.Debug($"Getting data finished in {sw.ElapsedMilliseconds}ms");

                List <String>       buffer = new List <String>();
                DataSource <String> ds     = new PathDataSource(path, _config.Extensions);

                LoggerBundle.Inform($"Start to crawl path '{path}'...");
                foreach (String file in ds.Get())
                {
                    buffer.Add(file);

                    Int32 bufferCount = buffer.Count;
                    if (bufferCount < _config.BufferSize)
                    {
                        if (bufferCount % (_config.BufferSize < 1337 ? _config.BufferSize : 1337) == 0)
                        {
                            LoggerBundle.Trace($"Adding files to buffer [{bufferCount}/{_config.BufferSize}] ...");
                        }
                        continue;
                    }

                    ProcessBuffer(ref buffer, ref tracks);
                }

                ProcessBuffer(ref buffer, ref tracks);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: tobiaswuerth/mux-core
 private static void Main(String[] args)
 {
     // mainly for debugging
     LoggerBundle.Trace("TEST");
     LoggerBundle.Debug("TEST");
     LoggerBundle.Inform("TEST");
     LoggerBundle.Warn(new Exception());
     LoggerBundle.Error(new Exception());
     LoggerBundle.Fatal(new Exception());
 }
コード例 #3
0
ファイル: DataContext.cs プロジェクト: tobiaswuerth/mux-data
        public DataContext(DbContextOptions <DataContext> options) : base(options)
        {
            LoggerBundle.Debug("Initializing data context...");
            try
            {
                _config = Configurator.Request <DatabaseConfig>(DatabaseSettingsFilePath);
            }
            catch (Exception ex)
            {
                LoggerBundle.Fatal("Could not load database config file", ex);
                Environment.Exit(1);
            }

            LoggerBundle.Debug("Context initialized.");
        }
コード例 #4
0
        protected override void OnInitialize()
        {
            LoggerBundle.Debug($"Initializing plugin '{Name}'...");

            if (!File.Exists(FingerprintCalculationExecutablePath))
            {
                LoggerBundle.Fatal(new FileNotFoundException(
                                       $"File '{FingerprintCalculationExecutablePath}' not found. Visit https://github.com/acoustid/chromaprint/releases to download the latest version."
                                       , FingerprintCalculationExecutablePath));
                Environment.Exit(1);
            }

            LoggerBundle.Trace("Requesting config...");
            _config = RequestConfig <Config>();
            LoggerBundle.Trace("Done");

            RegisterAction("include-failed", () => _includeFailed = true);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: tobiaswuerth/mux-cli
        private Program(String[] args)
        {
            LoggerBundle.Inform("Initializing...");

            (Boolean success, ProgramConfig config) = ProcessProgramArguments(args);
            if (!success)
            {
                LoggerBundle.Fatal("Program arguments could not be parsed correctly");
                Environment.Exit(1);
            }

            try
            {
                CreateGlobalDirectories();

                List <PluginBase> pluginsToLoad         = LoadPlugins();
                Dictionary <String, PluginBase> plugins = InitializePlugin(pluginsToLoad);

                String pluginName = config.PluginName.ToLower();
                if (!plugins.ContainsKey(pluginName))
                {
                    LoggerBundle.Warn($"No active plugin with name '{pluginName}' found");
                    LoggerBundle.Inform("The following plugin names were registered on startup: ");
                    plugins.Keys.ToList().ForEach(x => LoggerBundle.Inform($"+ {x}"));
                    return;
                }

                LoggerBundle.Inform("Executing plugin...");
                plugins[pluginName].Work(config.Args.ToArray());
                LoggerBundle.Inform("Execution finished.");
            }
            catch (Exception ex)
            {
                LoggerBundle.Error(ex);
            }
        }
コード例 #6
0
        private void AddUser()
        {
            LoggerBundle.Debug("Starting process to add new user...");
            try
            {
                // read username
                LoggerBundle.Inform(Logger.DefaultLogFlags & ~LogFlags.SuffixNewLine, "Enter a username: "******"";

                if (String.IsNullOrWhiteSpace(username))
                {
                    LoggerBundle.Fatal(new ArgumentException("Username cannot be empty"));
                    Environment.Exit(1);
                }

                // check existance
                LoggerBundle.Debug("Checking if user already exists...");
                Boolean exists;
                using (DataContext dataContext = DataContextFactory.GetInstance())
                {
                    exists = dataContext.SetUsers.Any(x => x.Username.ToLower().Equals(username.ToLower()));
                }
                if (exists)
                {
                    LoggerBundle.Fatal(new ArgumentException("Username already exists"));
                    Environment.Exit(1);
                }

                LoggerBundle.Trace("User not found database. Allowed to proceed forward");

                // get password
                LoggerBundle.Inform(Logger.DefaultLogFlags & ~LogFlags.SuffixNewLine, "Enter a password: "******"Confirm password: "******"Passwords do not match"));
                    Environment.Exit(1);
                }

                // hash password
                Sha512HashPipe hashPipe = new Sha512HashPipe();
                String         hashedPw = hashPipe.Process(pw1);

                // save model
                User user = new User
                {
                    Username   = username
                    , Password = hashedPw
                };
                using (DataContext dataContext = DataContextFactory.GetInstance())
                {
                    dataContext.SetUsers.Add(user);
                    dataContext.SaveChanges();
                }
                LoggerBundle.Inform(
                    $"Successfully created user '{user.Username}' created with unique identifier '{user.UniqueId}'");
            }
            catch (Exception ex)
            {
                LoggerBundle.Error(ex);
            }
        }