public void OnGetMeta(ServerMeta meta) { if (meta.Sub != null) { foreach (var sub in meta.Sub) { var userId = sub.UserId; var online = sub.Online; var topic = sub.Topic; var publicInfo = sub.Public.ToStringUtf8(); var subObj = JsonConvert.DeserializeObject <JObject>(publicInfo); string userName = topic; string type = subObj == null ? "group" : "user"; string photoData = string.Empty; string photoType = string.Empty; if (subObj != null) { userName = subObj["fn"].ToString(); if (subObj.ContainsKey("photo")) { photoData = subObj["photo"]["data"].ToString(); photoType = subObj["photo"]["type"].ToString(); } } AddSubscriber(new Subscriber(userId, topic, userName, type, photoData, photoType, online)); } } }
public Startup(IConfiguration configuration) { Configuration = configuration; var Currentdir = Directory.GetCurrentDirectory(); resfolderpath = Path.Combine(Currentdir, "res"); var conffolderpath = Path.Combine(Currentdir, "config"); var conffilepath = Path.Combine(Currentdir, "config", "config.json"); //Make sure we have the folders we need even if -setup wasnt specified if (!Directory.Exists(conffolderpath)) { Directory.CreateDirectory(conffolderpath); } if (!Directory.Exists(resfolderpath)) { Directory.CreateDirectory(resfolderpath); } if (!File.Exists(conffilepath)) { var buffer = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new ServerConfig(), Formatting.Indented)); var fs = File.Create(conffilepath); fs.WriteAsync(buffer, 0, buffer.Length).GetAwaiter().GetResult(); fs.DisposeAsync().GetAwaiter().GetResult(); Trace.WriteLine("A new configuration file was created. To customise, please either edit the newly created file or run the Setup Utility"); } _config = JsonConvert.DeserializeObject <ServerConfig>(File.ReadAllText(conffilepath)); _db = new Database(_config.Provider, _config.ConnectionString); _meta = new ServerMeta(); }
public ServerMetaEventArgs(ServerMeta meta) { Meta = meta; }
/// <summary> /// Server Ctor /// </summary> /// <param name="database"></param> /// <param name="meta"></param> public ServerController(Database database, ServerMeta meta) { this.Database = database; this.Meta = meta; }