Пример #1
0
        public bool Execute(string[] args)
        {
            if (!Validate(args))
            {
                return(false);
            }

            try
            {
                var access = new JsonLibraryAccess();
                var loader = new LibraryIO(args[0], access, access);
                jukeController.LoadHandler.LoadSongs(loader);
            } catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                return(false);
            }

            Console.WriteLine("");
            Console.WriteLine("JUKE Library stats: ");
            Console.WriteLine("Artists: " + jukeController.Browser.Artists.Count);
            Console.WriteLine("Albums: " + jukeController.Browser.Albums.Count);
            Console.WriteLine("Songs: " + jukeController.Browser.Songs.Count);
            Console.WriteLine("");

            return(true);
        }
Пример #2
0
 public void LoadLibrary()
 {
     LibraryBasis.Load(this);
     LibraryJson.Load(this);
     LibraryMath.Load(this);
     LibraryUserdata.Load(this);
     LibraryIO.Load(this);
 }
Пример #3
0
        private void LoadPromptOnTextEntered(object?sender, string filename)
        {
            var musicFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            var totalName   = Path.Combine(musicFolder, filename + ".xml");
            var access      = new XmlLibraryAccess();
            var io          = new LibraryIO(totalName, access, access);

            jukeControl.LoadHandler.LoadSongs(io);
            Invalidate(true);
        }
Пример #4
0
        private void SaveFileSelected(object?sender, string filename)
        {
            var musicFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);

            var totalName = Path.Combine(musicFolder, filename + ".xml");
            var access    = new XmlLibraryAccess();
            var io        = new LibraryIO(totalName, access, access);

            jukeControl.SaveLibrary(io);
            Messenger.Post("Library saved to " + totalName);
            Invalidate(true);
        }
Пример #5
0
 public void LoadLibrary()
 {
     LibraryBasis.Load(this);
     LibraryArray.Load(this);
     LibraryString.Load(this);
     LibraryTable.Load(this);
     LibraryJson.Load(this);
     LibraryMath.Load(this);
     LibraryFunc.Load(this);
     LibraryUserdata.Load(this);
     LibraryIO.Load(this);
 }
Пример #6
0
        private static void CheckIO(ILibrary library, LibraryIO io)
        {
            using (var memoryStream = new MemoryStream())
            {
                io.Save(library, memoryStream);
                memoryStream.Seek(0, SeekOrigin.Begin);
                var loaded = io.Load(memoryStream);

                Assert.AreEqual(library.Entries.Count, loaded.Entries.Count);

                for (var i = 0; i != library.Entries.Count; ++i)
                {
                    var expected = library.Entries[i];
                    var actual   = loaded.Entries[i];

                    Assert.AreEqual(expected, actual, string.Format("Puzzle #{0} not saved/loaded correctly", i));
                }
            }
        }
Пример #7
0
        public Script()
        {
            Global = new ScriptGlobal();

            TypeObject      = new ScriptTypeObject("Object");
            TypeObjectValue = new ScriptValue(TypeObject);
            Global.SetValue(TypeObject.TypeName, TypeObjectValue);

            AddPrimitivePrototype("Bool", ref m_TypeBool, ref m_TypeValueBool);
            AddPrimitivePrototype("Number", ref m_TypeNumber, ref m_TypeValueNumber);
            AddPrimitivePrototype("String", ref m_TypeString, ref m_TypeValueString);
            AddPrimitivePrototype("Function", ref m_TypeFunction, ref m_TypeValueFunction);

            AddBasicPrototype(m_TypeArray         = new ScriptTypeBasicArray(this, "Array", TypeObjectValue), ref m_TypeValueArray);
            AddBasicPrototype(m_TypeMap           = new ScriptTypeBasicMap(this, "Map", TypeObjectValue), ref m_TypeValueMap);
            AddBasicPrototype(m_TypeStringBuilder = new ScriptTypeBasicStringBuilder(this, "StringBuilder", TypeObjectValue), ref m_TypeValueStringBuilder);

            Global.SetValue(GLOBAL_NAME, new ScriptValue(Global));
            Global.SetValue(GLOBAL_SCRIPT, ScriptValue.CreateValue(this));
            Global.SetValue(GLOBAL_VERSION, ScriptValue.CreateValue(typeof(Version)));

            ProtoObject.Load(this, TypeObject);
            ProtoBoolean.Load(this, TypeBoolean);
            ProtoNumber.Load(this, TypeNumber);
            ProtoString.Load(this, TypeString);
            ProtoArray.Load(this, TypeArray);
            ProtoMap.Load(this, TypeMap);
            ProtoFunction.Load(this, TypeFunction);
            ProtoStringBuilder.Load(this, TypeStringBuilder);

            TypeManager.PushAssembly(typeof(object).Assembly);                        //mscorlib.dll
            TypeManager.PushAssembly(typeof(System.Net.Sockets.Socket).Assembly);     //System.dll
            TypeManager.PushAssembly(GetType().Assembly);                             //当前所在的程序集

            LibraryBasis.Load(this);
            LibraryJson.Load(this);
            LibraryMath.Load(this);
            LibraryUserdata.Load(this);
            LibraryIO.Load(this);
        }
Пример #8
0
        static void Main(string[] args)
        {
            script = new Script();
            script.LoadLibrary();
            script.PushAssembly(typeof(Program).GetTypeInfo().Assembly);
#if !SCORPIO_NET_CORE
            string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;
#else
            string CurrentDirectory = "";
#endif
            Console.WriteLine("the current version : " + Script.Version);
            Console.WriteLine("app path is : " + CurrentDirectory);
            LoadLibrary(Path.Combine(CurrentDirectory, "dll"));
            LoadFiles(Path.Combine(CurrentDirectory, "cs"));
            if (args.Length >= 1)
            {
                try {
                    string file = Path.GetFullPath(args[0]);
                    string path = Path.GetDirectoryName(file);
                    LoadLibrary(Path.Combine(path, "dll"));
                    LoadFiles(Path.Combine(path, "cs"));
                    Stopwatch watch = Stopwatch.StartNew();
                    script.PushSearchPath(CurrentDirectory);
                    script.PushSearchPath(path);
                    script.SetObject("__PATH__", path);
                    LibraryIO.Load(script);
                    Console.WriteLine("=============================");
                    ScriptObject value = script.LoadFile(file);
                    Console.WriteLine("=============================");
                    Console.WriteLine("return value : " + value);
                    Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms");
                } catch (System.Exception ex) {
                    Console.WriteLine(script.GetStackInfo());
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                while (true)
                {
                    try {
                        string str = Console.ReadLine();
                        if (str == "exit")
                        {
                            break;
                        }
                        else if (str == "clear")
                        {
                            Console.Clear();
                        }
                        else if (str == "version")
                        {
                            Console.WriteLine(Script.Version);
                        }
                        else
                        {
                            script.LoadString(str);
                        }
                    } catch (System.Exception ex) {
                        Console.WriteLine(script.GetStackInfo());
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Пример #9
0
        static void Execute(string[] args)
        {
            script = new Script();
            script.LoadLibrary();
            LibraryIO.Load(script);
            script.PushAssembly(typeof(Program).Assembly);
            Console.WriteLine("os version : " + Environment.OSVersion.ToString());
            Console.WriteLine("sco version : " + Scorpio.Version.version);
            Console.WriteLine("build date : " + Scorpio.Version.date);
            Console.WriteLine("app path is : " + BaseDirectory);
            Console.WriteLine("environment path is : " + CurrentDirectory);
            LoadLibrary(Path.Combine(CurrentDirectory, "dll"));
            if (args.Length >= 1)
            {
                try {
                    string    file  = Path.Combine(CurrentDirectory, args[0]);
                    string    path  = Path.GetDirectoryName(file);
                    Stopwatch watch = Stopwatch.StartNew();
                    script.PushSearchPath(path);
                    script.PushSearchPath(CurrentDirectory);
                    script.SetObject("__PATH__", path);
                    Console.WriteLine("=============================");
                    ScriptObject value = script.LoadFile(file);
                    Console.WriteLine("=============================");
                    Console.WriteLine("return value : " + value);
                    Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms");
                } catch (System.Exception ex) {
                    Console.WriteLine(script.GetStackInfo());
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                while (true)
                {
                    try {
                        string str = Console.ReadLine();
                        if (str == "exit")
                        {
                            break;
                        }
                        else if (str == "clear")
                        {
                            Console.Clear();
                        }
                        else if (str == "version")
                        {
                            Console.WriteLine($@"version : {Scorpio.Version.version}
build date : {Scorpio.Version.date}");
                        }
                        else
                        {
                            script.LoadString(str);
                        }
                    } catch (System.Exception ex) {
                        Console.WriteLine(script.GetStackInfo());
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Пример #10
0
        static void Main(string[] args)
        {
            string CurrentDirectory = AppDomain.CurrentDomain.BaseDirectory;

            if ((args.Length == 1 && args[0] == "__RegisterEnvironment"))
            {
                var p = new List <string>(Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User).Split(';'));
                if (!p.Contains(CurrentDirectory))
                {
                    p.Add(CurrentDirectory);
                    Environment.SetEnvironmentVariable("Path", string.Join(";", p.ToArray()), EnvironmentVariableTarget.User);
                }
                Console.WriteLine("path is already existed");
                return;
            }
            script = new Script();
            script.LoadLibrary();
            script.PushAssembly(typeof(Program).GetTypeInfo().Assembly);
            Console.WriteLine("the current version : " + Script.Version);
            Console.WriteLine("app path is : " + CurrentDirectory);
            LoadLibrary(Path.Combine(CurrentDirectory, "dll"));
            LoadFiles(Path.Combine(CurrentDirectory, "cs"));
            if (args.Length >= 1)
            {
                try {
                    string file = Path.GetFullPath(args[0]);
                    string path = Path.GetDirectoryName(file);
                    LoadLibrary(Path.Combine(path, "dll"));
                    LoadFiles(Path.Combine(path, "cs"));
                    Stopwatch watch = Stopwatch.StartNew();
                    script.PushSearchPath(CurrentDirectory);
                    script.PushSearchPath(path);
                    script.SetObject("__PATH__", path);
                    script.SetObject("print", script.CreateFunction(new print()));
                    LibraryIO.Load(script);
                    Console.WriteLine("=============================");
                    ScriptObject value = script.LoadFile(file);
                    Console.WriteLine("=============================");
                    Console.WriteLine("return value : " + value);
                    Console.WriteLine("the execution time : " + watch.ElapsedMilliseconds + " ms");
                } catch (System.Exception ex) {
                    Console.WriteLine(script.GetStackInfo());
                    Console.WriteLine(ex.ToString());
                }
            }
            else
            {
                while (true)
                {
                    try {
                        string str = Console.ReadLine();
                        if (str == "exit")
                        {
                            break;
                        }
                        else if (str == "clear")
                        {
                            Console.Clear();
                        }
                        else if (str == "version")
                        {
                            Console.WriteLine(Script.Version);
                        }
                        else
                        {
                            script.LoadString(str);
                        }
                    } catch (System.Exception ex) {
                        Console.WriteLine(script.GetStackInfo());
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Пример #11
0
        static void Main(string[] args)
        {
            Script script = new Script();

            Console.WriteLine("开始执行,当前版本:" + Script.Version);
            script.LoadLibrary();
            script.PushAssembly(typeof(Program).Assembly);
            if (Directory.Exists(CurrentDirectory + "/Library"))
            {
                string[] files = Directory.GetFiles(CurrentDirectory + "/Library", "*.dll", SearchOption.AllDirectories);
                foreach (var file in files)
                {
                    try {
                        script.PushAssembly(Assembly.LoadFile(file));
                        Console.WriteLine("导入文件[" + file + "]成功");
                    } catch (System.Exception ex) {
                        Console.WriteLine("导入文件[" + file + "]失败 " + ex.ToString());
                    }
                }
            }
            if (Directory.Exists(CurrentDirectory + "/Program"))
            {
                try {
                    script.PushAssembly(CompilerFile(CurrentDirectory + "/Program"));
                } catch (System.Exception ex) {
                    Console.WriteLine("编译文件失败 " + ex.ToString());
                }
            }
            if (args.Length >= 1)
            {
                try {
                    Stopwatch watch = Stopwatch.StartNew();
                    script.PushSearchPath(CurrentDirectory);
                    script.PushSearchPath(Path.GetDirectoryName(args[0]));
                    LibraryIO.Load(script);
                    Console.WriteLine("返回值为:" + script.LoadFile(args[0]));
                    Console.WriteLine("运行时间:" + watch.ElapsedMilliseconds + " ms");
                } catch (System.Exception ex) {
                    Console.WriteLine(script.GetStackInfo());
                    Console.WriteLine(ex.ToString());
                }
                Console.ReadKey();
            }
            else
            {
                while (true)
                {
                    try {
                        string str = Console.ReadLine();
                        if (str == "exit")
                        {
                            break;
                        }
                        else if (str == "clear")
                        {
                            Console.Clear();
                        }
                        else if (str == "version")
                        {
                            Console.WriteLine(Script.Version);
                        }
                        else
                        {
                            script.LoadString(str);
                        }
                    } catch (System.Exception ex) {
                        Console.WriteLine(script.GetStackInfo());
                        Console.WriteLine(ex.ToString());
                    }
                }
            }
        }
Пример #12
0
        private void CheckCondensedFormatIO(ILibrary library)
        {
            var io = new LibraryIO(new CondensedFormat());

            CheckIO(library, io);
        }
Пример #13
0
        private void CheckReadableFormatIO(ILibrary library)
        {
            var io = new LibraryIO(new ReadableFormat());

            CheckIO(library, io);
        }