public SubscriptionRouter( BroadcastingTunnel tunnel, ClientApplication app ) { this.tunnel = tunnel; this.app = app; http = app.Resolve <AssetHttpClient>(); url = app.Resolve <ApiUrl>(); sessionIdRepository = app.Resolve <ClientSessionIdRepository>(); tunnel.OnMessageEvent += OnMessageEvent; tunnel.OnSubscriptionEvent += OnSubscriptionEvent; }
private void PerformContainerSurgery(Application serverApp) { // replace the database instance var arangoRepo = clientApp.Resolve <ArangoRepository>(); arango = arangoRepo.GetDatabase( clientApp.Preferences.EmulatedDatabaseName ); serverApp.Instance <IArango>(arango); clientApp.DontDisposeInstance(arango); // replace session instance var session = new SessionOverStorage( new EmulatedSessionStorage(arango), 3600 ); serverApp.Instance <ISession>(session); }
protected override IPromise <JsonValue> PerformFacetCall( string facetName, string methodName, JsonArray arguments ) { var promise = new Promise <JsonValue>(); http.Post( app.Resolve <ApiUrl>().CallFacet(), new JsonObject() .Add("facetName", facetName) .Add("methodName", methodName) .Add("arguments", arguments) .Add("sessionId", SessionId) .Add("deviceId", DeviceIdRepository.GetDeviceId()) .Add("device", DeviceIdRepository.GetDeviceInfo()) .Add("gameToken", app.Preferences.GameToken) .Add("editorKey", app.Preferences.EditorKey) .Add("client", new JsonObject() .Add("backendHash", app.Preferences.BackendHash) .Add("frameworkVersion", FrameworkMeta.Version) .Add("assetVersion", AssetMeta.Version) .Add("buildGuid", Application.buildGUID) .Add("versionString", Application.version) ), response => { if (response.IsOk) { HandleSuccessfulRequest(response, promise); } else { HandleFailedRequest(response, promise); } } ); return(promise); }
public virtual void SetUp() { // create testing client application ClientApp = new ClientApplication( UnisavePreferences.LoadOrCreate() ); // prepare environment var env = new EnvStore(); DownloadEnvFile(env); // create testing backend application App = Bootstrap.Boot( GetGameAssemblyTypes(), env, new SpecialValues() ); // execute backend code locally ClientApp.Singleton <FacetCaller>( _ => new TestingFacetCaller(App, ClientApp) ); // logging should go direct, we don't want to wait for app disposal // for writing logs to special values // HACK: this is a hack, see the ClientSideLog class for more App.Singleton <ILog>(_ => new ClientSideLog()); // bind facades Facade.SetApplication(App); ClientFacade.SetApplication(ClientApp); // start with a blank slate ClientApp.Resolve <ClientSessionIdRepository>().StoreSessionId(null); ClearDatabase(); }
public UnisaveFacetCaller(ClientApplication app) : base(app) { this.app = app; http = app.Resolve <AssetHttpClient>(); }
protected override IPromise <JsonValue> PerformFacetCall( string facetName, string methodName, JsonArray arguments ) { var promise = new Promise <JsonValue>(); Http.Post( app.Resolve <ApiUrl>().CallFacet(), new JsonObject() .Add("facetName", facetName) .Add("methodName", methodName) .Add("arguments", arguments) .Add("sessionId", SessionId) .Add("deviceId", DeviceIdRepository.GetDeviceId()) .Add("device", DeviceIdRepository.GetDeviceInfo()) .Add("gameToken", app.Preferences.GameToken) .Add("editorKey", app.Preferences.EditorKey) .Add("client", new JsonObject() .Add("backendHash", app.Preferences.BackendHash) .Add("frameworkVersion", FrameworkMeta.Version) .Add("assetVersion", AssetMeta.Version) .Add("buildGuid", Application.buildGUID) .Add("versionString", Application.version) ), "200" ).Then(response => { JsonObject executionResult = response["executionResult"]; JsonObject specialValues = executionResult["special"].AsJsonObject ?? new JsonObject(); // remember the session id string givenSessionId = specialValues["sessionId"].AsString; if (givenSessionId != null) { SessionId = givenSessionId; } // print logs LogPrinter.PrintLogsFromFacetCall(specialValues["logs"]); switch (executionResult["result"].AsString) { case "ok": promise.Resolve(executionResult["returned"]); break; case "exception": var e = Serializer.FromJson <Exception>( executionResult["exception"] ); PreserveStackTrace(e); promise.Reject(e); break; default: promise.Reject( new UnisaveException( "Server sent unknown response for facet call:\n" + response ) ); break; } }).Catch(e => { if (e is HttpException he) { if (he.Response.StatusCode == 422) { Debug.LogError( "Facet call failed:\n" + he.Response.TextContent ); } } promise.Reject(e); }); return(promise); }