public void LoadPathProfile(string pathFilename) { StopBot(); if (InitialiseFromFile(SelectedClassFilename, pathFilename)) { SelectedPathFilename = pathFilename; } ProfileLoaded?.Invoke(this, EventArgs.Empty); }
public static void LoadProfile(string name) { var path = Path.Combine(GetProfilesDirectory(), name); var backupPath = $"{path}.backup"; if (!File.Exists(path) && !File.Exists(backupPath)) { throw new FileNotFoundException($"Couldn't find profile at {path}.", path); } Profile loadedProfile = null; try { loadedProfile = DeserializeProfile(path); } catch (Exception e0) { if (File.Exists(backupPath)) { L.Warn($"Trying to load backup after failed to load profile {name}"); try { if (File.Exists(backupPath)) { loadedProfile = DeserializeProfile(backupPath); } } catch (Exception e1) { throw new GameException(3, e1, "Failed to deserialize profile and its backup."); } } else { throw new GameException(2, e0, "Failed to deserialize profile."); } } lock (opLock) { Profile = loadedProfile; currentProfileName = name; } ProfileLoaded?.Invoke(); }
public static void LoadProfile(Profile profile, string name) { if (profile == null) { throw new ArgumentNullException(nameof(profile)); } if (String.IsNullOrEmpty(name)) { throw new ArgumentException($"Invalid profile name: {name}", nameof(name)); } lock (opLock) { Profile = profile; currentProfileName = name; } ProfileLoaded?.Invoke(); }
private void WebsocketHandlerOnMessageReceived(object sender, string message) { try { dynamic data = JsonConvert.DeserializeObject(message); if (data.code >= 400) { Invoke(ApiError, data); return; } if (data.meta is JObject meta && meta.TryGetValue("event", out var metaEvent)) { var eventName = metaEvent.Value <string>(); log.Debug($"Received ws message with event '{eventName}', posting to eventbus"); switch (eventName) { case ApiEventNames.Connection: if (data.result?.attributes is JObject welcome && welcome.TryGetValue("version", out var versionString)) { Version.TryParse(versionString.Value <string>(), out var version); Invoke(ConnectionEstablished, version); } break; case ApiEventNames.StreamSubscribe: break; case ApiEventNames.UserProfile: var user = JsonApi.Deserialize <User>(message); ProfileLoaded?.Invoke(this, user); break; case ApiEventNames.RescueCreated: var rescues = JsonApi.Deserialize <Rescue[]>(message); foreach (var rescue in rescues) { Invoke(RescueCreated, rescue); } break; case ApiEventNames.RescueUpdated: rescues = JsonApi.Deserialize <Rescue[]>(message); foreach (var rescue in rescues) { if (rescue.Status == RescueState.Closed) { Invoke(RescueClosed, rescue); return; } Invoke(RescueUpdated, rescue); } break; case ApiEventNames.RescueRead: rescues = JsonApi.Deserialize <Rescue[]>(message); Invoke(RescuesReloaded, rescues); break; default: log.Debug($"Received unmapped message: event '{eventName}', message '{message}'"); break; } } } catch (Exception ex) { log.Fatal("Exception in WSClient_MessageReceived: " + ex.Message, ex); } }