Esempio n. 1
0
        private static async Task LoadJsonModelIntoGeneratedJsonSchemaView(
            ViewStack viewStack, ModelToJsonSchema schemaGenerator, JsonSchema schema, string jsonModel)
        {
            JObject          model         = JsonReader.GetReader().Read <JObject>(jsonModel);
            JsonSchemaToView viewGenerator = new JsonSchemaToView(schemaGenerator);
            GameObject       generatedView = await viewGenerator.ToView(schema);

            viewStack.ShowView(generatedView);

            var presenter = new JsonSchemaPresenter(viewGenerator);

            presenter.targetView = generatedView;

            Log.d("Model BEFORE changes: " + model.ToPrettyString());
            var changedModel = await presenter.LoadModelIntoView(model.DeepClone() as JObject);

            await JsonSchemaPresenter.ChangesSavedViaConfirmButton(generatedView);

            Log.d("Model AFTER changes: " + changedModel.ToPrettyString());

            viewStack.SwitchBackToLastView(generatedView);
            var changedFields = MergeJson.GetDiff(model, changedModel);

            Log.d("Fields changed: " + changedFields?.ToPrettyString());
        }
Esempio n. 2
0
        private static async Task LoadModelIntoGeneratedView(ViewStack viewStack, ModelToJsonSchema schemaGenerator, JsonSchema schema)
        {
            MyUserModel model = NewExampleUserInstance();
            {
                await Dialog.ShowInfoDialog("Manually connecting the model instance to the view", "First an example to connect the " +
                                            "model to a generated view via a manual presenter 'MyManualPresenter1'", "Show manual presenter example");

                var        viewGenerator = new JsonSchemaToView(schemaGenerator);
                GameObject generatedView = await viewGenerator.ToView(schema);

                viewStack.ShowView(generatedView);

                var presenter = new MyManualPresenter1();
                presenter.targetView = generatedView;

                Log.d("Model BEFORE changes: " + JsonWriter.AsPrettyString(model));
                await presenter.LoadModelIntoView(model);

                viewStack.SwitchBackToLastView(generatedView);
                Log.d("Model AFTER changes: " + JsonWriter.AsPrettyString(model));
            }
            {
                await Dialog.ShowInfoDialog("Using JsonSchemaPresenter to autmatically connect the model instance and view",
                                            "The second option is to use a generic JObjectPresenter to connect the model to the generated view",
                                            "Show JsonSchemaPresenter example");

                var        viewGenerator = new JsonSchemaToView(schemaGenerator);
                GameObject generatedView = await viewGenerator.ToView(schema);

                viewStack.ShowView(generatedView);

                var presenter = new JsonSchemaPresenter(viewGenerator);
                presenter.targetView = generatedView;

                Log.d("Model BEFORE changes: " + JsonWriter.AsPrettyString(model));
                MyUserModel changedModel = await presenter.LoadViaJsonIntoView(model);

                viewStack.SwitchBackToLastView(generatedView);

                Log.d("Model AFTER changes: " + JsonWriter.AsPrettyString(changedModel));
                var changedFields = MergeJson.GetDiff(model, changedModel);
                Log.d("Fields changed: " + changedFields?.ToPrettyString());
            }
        }