Ejemplo n.º 1
0
 private static void Main()
 {
     Client = new MusixClient("955b354ccd0e4270b6ad97f8b4003d9a", "5a008b85c33b499da7857fbdf05f08ef", "ImageCache", "AudioCache");
     Client.StartClient();
     Client.OnClientReady += Client_OnClientReady;
     c.WriteLine($"Creating client with conversion provider {Client.ConversionsProvider.GetType().FullName}");
     Thread.Sleep(-1);
 }
Ejemplo n.º 2
0
        private void MainWindow_Load(object sender, EventArgs e)
        {
            Instance = this;
            DateTime Started     = DateTime.Now;
            FileInfo AppBaseInfo = new FileInfo(Application.ExecutablePath);

            Environment.CurrentDirectory = AppBaseInfo.DirectoryName;
            ConfigManager.Init();

            CheckFolders();

            DateTime PStarted = DateTime.Now;

            foreach (string PluginFile in Directory.GetFiles("Plugins", "*.dll"))
            {
                FileInfo info = new FileInfo(PluginFile);
                try
                {
                    Console.WriteLine($"Loading plugin {info.Name}...");
                    List <string> Deps = new List <string>();
                    if (Directory.Exists(Path.Combine("Plugins", info.Name)))
                    {
                        foreach (string Dependancy in Directory.GetFiles(Path.Combine("Plugins", info.Name), "*.dll"))
                        {
                            Deps.Add(Dependancy);
                        }
                    }
                    Console.WriteLine($"Loading {Deps.Count} dependancies for plugin {info.Name}...");
                    Deps.ForEach(x => Assembly.LoadFrom(x));

                    Assembly Plugin = Assembly.LoadFrom(PluginFile);
                    foreach (Type t in Plugin.GetTypes())
                    {
                        if (typeof(IMusixPluginEntryPoint).IsAssignableFrom(t))
                        {
                            Console.WriteLine($"Initializing plugin {info.Name}...");
                            IMusixPluginEntryPoint entryPoint = ((IMusixPluginEntryPoint)Activator.CreateInstance(t));
                            entryPoint.Load();
                            Plugins.Add(entryPoint.Name, entryPoint);
                            Console.WriteLine($"Initialized plugin {entryPoint.Name}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine($"Failed to load plugin {info.Name}; {ex.Message}");
                    Console.WriteLine(ex.Message);
                }
            }
            Console.WriteLine($"[Plugins Loaded] took {Math.Round(DateTime.Now.Subtract(PStarted).TotalMilliseconds),2} millisecond/s.");


            Client = new MusixClient("955b354ccd0e4270b6ad97f8b4003d9a", "5a008b85c33b499da7857fbdf05f08ef", "ImageCache", "AudioCache");
            Client.OnClientReady += Client_OnClientReady;
            Client.StartClient();

            AcceptButton = new Button();

            Activated  += MainWindow_Activated;
            Deactivate += MainWindow_Deactivate;
            ((Button)AcceptButton).Click += BtnAccept_Click;

            MenuItems.Add(typeof(SearchMenuItem), new SearchMenuItem());
            MenuItems.Add(typeof(DownloadsMenuItem), new DownloadsMenuItem());
            MenuItems.Add(typeof(SettingsMenuItem), new SettingsMenuItem());
            MDSSideBar.AddItem(MenuItems[typeof(SearchMenuItem)]);
            MDSSideBar.AddItem(MenuItems[typeof(DownloadsMenuItem)]);
            MDSSideBar.AddItem(MenuItems[typeof(SettingsMenuItem)]);

            foreach (Assembly asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (Type t in asm.GetTypes().Where(x => typeof(IMusixMenuItem).IsAssignableFrom(x) && !x.IsInterface))
                {
                    if (!MenuItems.ContainsKey(t))
                    {
                        IMusixMenuItem newItem = (IMusixMenuItem)Activator.CreateInstance(t);
                        MDSSideBar.AddItem(newItem);
                        MenuItems.Add(t, newItem);
                    }
                }
            }

            foreach (var item in MenuItems)
            {
                if (Attribute.GetCustomAttribute(item.Value.GetType(), typeof(AutoInitialize)) != null)
                {
                    Control ct = item.Value.GetMenuControl();
                    ct.Visible = false;
                    ct.Dock    = DockStyle.Fill;
                    if (!PNContent.Controls.Contains(ct))
                    {
                        PNContent.Controls.Add(ct);
                    }
                }
            }

            MDSSideBar.OnSelectionChanged += MDSSideBar_OnSelectionChanged;

            MDSSideBar.SelectItemAtIndex(0);
            SendStyle(EStyle.Blue);

            DateTime Finished = DateTime.Now;

            Console.WriteLine($"[Initialized] took {Math.Round(Finished.Subtract(Started).TotalMilliseconds), 3} millisecond/s.");
        }