protected void ConvertToLevel(string jsonPath, string levelPath, string outPath)
        {
            Console.WriteLine("LEVEL " + outPath + " " + jsonPath + " " + levelPath);
            IMap map = new Map(File.ReadAllBytes(levelPath));
            string jsonStr = File.ReadAllText(jsonPath);

            JsonMapParser jsonMapParser = new JsonMapParser();
            jsonMapParser.ImportJson(map, jsonStr);

            Directory.CreateDirectory(Path.GetDirectoryName(outPath));
            File.WriteAllBytes(outPath, map.Write());
        }
        public void OnChangeJson(string path)
        {
            string levelPath;
            string jsonPath;
            DateTime saveTime;
            string backupDir;
            bool createBackups;
            lock (ThreadLock)
            {
                createBackups = CreateBackups;
                backupDir = BackupDir;
                levelPath = LevelPath;
                jsonPath = JsonPath;
                saveTime = saveLevelTime;
            }

            ThreadPool.QueueUserWorkItem((object state) =>
            {
                lock (ThreadLock)
                {
                    if (saveTime == null || (DateTime.Now - saveTime).TotalMilliseconds > 50)
                    {
                        if (createBackups && !String.IsNullOrWhiteSpace(backupDir))
                        {
                            Directory.CreateDirectory(backupDir);
                            string levelName = Path.GetFileName(LevelPath);
                            string backup = MapUtils.FindNextFileVersionName(Path.Combine(backupDir, levelName));
                            OnEvent(String.Format("Creating backup at '{0}'", backup));
                            File.Copy(levelPath, backup);
                        }
                        OnEvent(String.Format("Parsing '{0}'", jsonPath));


                        IMap map = new Map(File.ReadAllBytes(levelPath));
                        string jsonStr = File.ReadAllText(path);

                        JsonMapParser jsonMapParser = new JsonMapParser();
                        jsonMapParser.ImportJson(map, jsonStr);

                        OnEvent(String.Format("Rebuilding '{0}'", Path.GetFileName(levelPath)));

                        Directory.CreateDirectory(Path.GetDirectoryName(levelPath));
                        File.WriteAllBytes(levelPath, map.Write());

                        OnEvent(String.Format("Finished rebuilding '{0}'", Path.GetFileName(levelPath)));

                        
                        saveJsonTime = DateTime.Now;
                    }
                }
            });
        }