private static MiMapConfig GetConfig() { try { Directory.CreateDirectory(BasePath); var configPath = Path.Combine(BasePath, "config.json"); if (!File.Exists(configPath)) { // Create config file var newConfig = new MiMapConfig(); var newConfigJson = MiMapJsonConvert.SerializeObject(newConfig, true); File.WriteAllText(configPath, newConfigJson); Log.InfoFormat("Generating Config..."); return(ProcessConfig(newConfig)); } var json = File.ReadAllText(configPath); var config = MiMapJsonConvert.DeserializeObject <MiMapConfig>(json); Log.InfoFormat("Config Loaded from {0}", configPath); return(ProcessConfig(config)); } catch (Exception ex) { Log.InfoFormat("Exception while loading MiMap Config:\n{0}", ex); throw; } }
public void Save() { lock (_ioSync) { if (!_isDirty) { return; } try { Directory.CreateDirectory(Path.GetDirectoryName(FilePath)); using (var fs = new FileStream(FilePath, FileMode.OpenOrCreate, FileAccess.Write)) { //using (var gs = new GZipStream(fs, CompressionMode.Compress)) { using (var sr = new StreamWriter(fs)) { //BlockColumnMeta[,] blocks = (BlockColumnMeta[,])Blocks.Clone(); var json = MiMapJsonConvert.SerializeObject(Blocks); sr.Write(json); } } } _isDirty = false; } catch (Exception ex) { Log.Error("Exception saving region meta for " + Position, ex); } } }
internal void ConfigureHttp(IAppBuilder app) { app.Map("/widgets/config.json", builder => { builder.Use( (context, next) => context.Response.WriteAsync(MiMapJsonConvert.SerializeObject(Widgets.ToArray()))); }); }
private void UpdateMeta() { Meta.LastUpdate = DateTime.UtcNow; Meta.Size = new Size(BlockBounds.Width, BlockBounds.Height); Meta.Bounds = BlockBounds; var json = MiMapJsonConvert.SerializeObject(Meta); File.WriteAllText(_metaPath, json); }
public ILayerRenderer Create(MiMapRendererConfig config) { if (ConfigType == null) { return(Activator.CreateInstance(RendererType) as ILayerRenderer); } else { var c = MiMapJsonConvert.DeserializeObject(MiMapJsonConvert.SerializeObject(config), ConfigType); return(Activator.CreateInstance(RendererType, c) as ILayerRenderer); } }
private void InitLevelRunners() { File.WriteAllText(Path.Combine(Config.TilesDirectory, "levels.json"), MiMapJsonConvert.SerializeObject(Config.Levels)); foreach (var levelConfig in MiMapManager.Config.Levels) { var levelMap = MiMapManager.GetLevelMap(levelConfig.LevelId); if (levelMap != null) { var runner = new LevelRunner(Context.Server, levelMap); _levelRunners.Add(levelConfig.LevelId, runner); } } }
public void UpdateBlockColumn(BlockColumnMeta column) { _updates.Enqueue(MiMapJsonConvert.DeserializeObject <BlockColumnMeta>(MiMapJsonConvert.SerializeObject(column))); }
public static string Encode <TPacket>(this TPacket packet) where TPacket : IPacket { return(MiMapJsonConvert.SerializeObject(packet)); }
protected virtual void OnInput(string json) { Log.WarnFormat("Unhandled Widget Input for type {0} with ID {1}:\n\t{2}", GetType().Name, ElementId, MiMapJsonConvert.SerializeObject(this)); }