Ejemplo n.º 1
0
        private List <ISnippet> Load()
        {
            var console = OutMgr.CreateConsole();

            if (!Directory.Exists("Snippets"))
            {
                console.WriteLine("Directory 'Snippets' is empty. New folder has been created.", OutLevel.Warning);

                Directory.CreateDirectory("Snippets");
            }

            List <ISnippet> snippets = new List <ISnippet>();


            var assemblies = Directory.GetFiles("Snippets");

            if (assemblies.Length > 0)
            {
                foreach (var assembly in assemblies)
                {
                    try
                    {
                        var ass      = Assembly.LoadFile(AppDomain.CurrentDomain.BaseDirectory + assembly);
                        var type     = ass.GetTypes().Where((x) => typeof(ISnippet).IsAssignableFrom(x)).Single();
                        var instance = (ISnippet)type.GetConstructor(Type.EmptyTypes)?.Invoke(null);

                        instance.OnLoaded();
                        snippets.Add(instance);
                    }
                    catch (Exception ex)
                    {
                        console.WriteLine($"Error occured while loading snippet: '{assembly}'", OutLevel.Error);
                        console.Except(ex);
                    }
                }
            }
            else
            {
                console.WriteLine("Not have a snippet for loading", OutLevel.Warning);
            }

            return(snippets);
        }
Ejemplo n.º 2
0
        public void Call(string name, params object[] data)
        {
            bool result = false;

            foreach (var snippet in LoadedSnippets)
            {
                if (snippet.GetType().Name.ToLower().Contains(name.ToLower()))
                {
                    OnSnippetCalled?.Invoke(snippet);

                    snippet.Run(data);
                    result = true;

                    break;
                }
            }

            if (!result)
            {
                OutMgr.CreateConsole().WriteLine("No snippet found to process this command", OutLevel.Error);
            }
        }
Ejemplo n.º 3
0
        public void Call <T>(params object[] data)
        {
            bool result = false;

            foreach (var snippet in LoadedSnippets)
            {
                if (snippet.GetType() == typeof(T))
                {
                    OnSnippetCalled?.Invoke(snippet);

                    snippet.Run(data);
                    result = true;

                    break;
                }
            }

            if (!result)
            {
                OutMgr.CreateConsole().WriteLine("No snippet found to process this command", OutLevel.Error);
            }
        }
Ejemplo n.º 4
0
 protected virtual BaseOut GetConsole()
 {
     return(OutMgr.CreateConsole());
 }
Ejemplo n.º 5
0
 public LoadCreaturesCommand()
 {
     Console = OutMgr.CreateConsole();
 }