private void AddRemoveConnection(AttachmentKind kind, AttachedGrid attached, bool add) { Attachments attach; if (!Connections.TryGetValue(attached, out attach)) { if (add) { attach = new Attachments(myGrid, attached.myGrid); Connections.Add(attached, attach); } else { Log.AlwaysLog("cannot remove, no attachments of kind " + kind, Logger.severity.ERROR); return; } } if (add) { attach.Add(kind); } else { attach.Remove(kind); } }
private static async Task LoadEmoticons(UserModel user, LockedDictionary <string, LockedDictionary <string, EmoticonImage> > storage) { List <EmoticonPackModel> userPacks = (await ChannelSession.Connection.GetEmoticons(ChannelSession.Channel, user)).ToList(); foreach (EmoticonPackModel userPack in userPacks) { if (!storage.ContainsKey(userPack.channelId.ToString())) { storage.Add(userPack.channelId.ToString(), new LockedDictionary <string, EmoticonImage>()); } foreach (KeyValuePair <string, EmoticonGroupModel> emoticon in userPack.emoticons) { storage[userPack.channelId.ToString()][emoticon.Key] = new EmoticonImage { Name = emoticon.Key, Uri = userPack.url, X = emoticon.Value.x, Y = emoticon.Value.y, Width = emoticon.Value.width, Height = emoticon.Value.height, }; } } }
public TAsset Load <TAsset>(string path, bool liveReload = false) where TAsset : IAsset { if (Disposed) { throw new InvalidOperationException("Cannot call Load on a disposed AssetManager."); } path = Path.GetFullPath(Path.Combine(RootPath, path)); if (path == null) { throw new ArgumentNullException(nameof(path)); } path = path.Replace('\\', '/') .Replace('/', Path.DirectorySeparatorChar); if (_assetCache.TryGetValue(path, out var cachedAsset)) { if (!(cachedAsset is TAsset castCached)) { throw new ArgumentException($"Cached asset of type \"{cachedAsset.GetType().Name}\" cannot be " + $"loaded as type \"{typeof(TAsset).FullName}\"."); } return(castCached); } if (!AssetLoaders.TryGetValue(typeof(TAsset), out IAssetLoader loader)) { throw new ArgumentException("AssetManager does not contain a loader for type " + $"\"{typeof(TAsset).FullName}\"."); } if (!(loader is IAssetLoader <TAsset> typedLoader)) { throw new Exception($"Invalid registered loader for type \"{typeof(TAsset).FullName}\"."); } var stream = GetStreamFromPath(path); TAsset asset = typedLoader.Load(this, RenderContext, stream, path); asset.SourcePath = path; asset.AssetManager = this; _loadedAssets.Add(asset); _assetCache.Add(path, asset); OnAssetLoaded(asset, liveReload); return(asset); }
public void UpdateLockedModel(string key) { Thread.CurrentThread.Join(200); lock (_lock) { if (LockedDictionary.ContainsKey(key)) { LockedDictionary[key].Count++; } else { LockedDictionary.Add(key, new DataCountModel { Count = 1 }); } } }
public void Add(L2Object obj) { if (obj == null) { return; } if (obj is L2Player) { _players.Add(obj.ObjectId, (L2Player)obj); foreach (L2WorldRegion region in GetClosestNeighbours().Where(x => !x.IsActive)) { region.Activate(); } } else { _objects.Add(obj.ObjectId, obj); } }
private static async Task LoadUserEmoticons() { // Read Manifest (built in) using (HttpClient httpClient = new HttpClient()) { httpClient.DefaultRequestHeaders.Add("User-Agent", $"MixItUp/{System.Reflection.Assembly.GetEntryAssembly().GetName().Version.ToString()} (Web call from Mix It Up; https://mixitupapp.com; [email protected])"); using (HttpResponseMessage response = await httpClient.GetAsync(ChannelSession.DefaultEmoticonsManifest)) { if (response.StatusCode == System.Net.HttpStatusCode.OK) { Dictionary <string, BuiltinEmoticonPack> manifest = JsonConvert.DeserializeObject <Dictionary <string, BuiltinEmoticonPack> >(await response.Content.ReadAsStringAsync()); foreach (KeyValuePair <string, BuiltinEmoticonPack> pack in manifest) { if (!builtinEmoticons.ContainsKey(pack.Key)) { builtinEmoticons.Add(pack.Key, new LockedDictionary <string, EmoticonImage>()); } string imageLink = string.Format(ChannelSession.DefaultEmoticonsLinkFormat, pack.Key); foreach (KeyValuePair <string, EmoticonGroupModel> emoticon in pack.Value.emoticons) { builtinEmoticons[pack.Key][emoticon.Key] = new EmoticonImage { Name = emoticon.Key, Uri = imageLink, X = emoticon.Value.x, Y = emoticon.Value.y, Width = emoticon.Value.width, Height = emoticon.Value.height, }; } } } } } await LoadEmoticons(ChannelSession.User, userEmoticons); }
/// <summary> /// End a profiling block, must be invoked even if an exception is thrown after block started. /// </summary> public static void EndProfileBlock([CallerMemberName] string callerMemberName = null, [CallerFilePath] string callerFilePath = null) { var block = BlockStack.Pop(); var elapsed = new MyTimeSpan(Stopwatch.GetTimestamp() - block.StartedAt); string startedIn = Path.GetFileName(block.CallerFilePath) + ',' + block.CallerMemberName; string endingIn = Path.GetFileName(callerFilePath) + ',' + callerMemberName; if (startedIn != endingIn) { throw new Exception($"Block was started in {startedIn} but ended in {endingIn}"); } ModProfiler profiler; if (!ModProfilers.TryGetValue(block.CallerAssembly, out profiler)) { profiler = new ModProfiler(block.CallerAssembly); ModProfilers.Add(block.CallerAssembly, profiler); } profiler.BlockClosed(block, elapsed, BlockStack.Count == 0); }