public async Task TestPostFormData() { // Use postman-echo.com to test posting form data including files: RestRequest request = new Uri("https://postman-echo.com/post").SendPOST(); DirectoryEntry dir = EnvironmentV2.instance.GetNewInMemorySystem(); FileEntry fileToUpload = dir.GetChild("test.txt"); fileToUpload.SaveAsText(GenerateLongStringForTextFile()); request.AddFileViaForm(fileToUpload); float progressInPercent = 0; request.onProgress = (newProgress) => { progressInPercent = newProgress; }; string formText = "I am a string"; request.WithFormContent(new Dictionary <string, object>() { { "formString1", formText } }); PostmanEchoResponse result = await request.GetResult <PostmanEchoResponse>(); Log.d(JsonWriter.AsPrettyString(result)); Assert.Single(result.form); Assert.Equal(100, progressInPercent); Assert.Equal(formText, result.form.First().Value); Assert.Single(result.files); Assert.Equal(fileToUpload.Name, result.files.First().Key); Assert.True(result.headers.contentType.StartsWith("multipart/form-data")); }
public async Task ExampleUsage2() { // Get your key from https://console.developers.google.com/apis/credentials var apiKey = "AIzaSyCtcFQMgRIUHhSuXggm4BtXT4eZvUrBWN0"; // See https://docs.google.com/spreadsheets/d/1Hwu4ZtRR0iXD65Wuj_XyJxLw4PN8SE0sRgnBKeVoq3A var sheetId = "1Hwu4ZtRR0iXD65Wuj_XyJxLw4PN8SE0sRgnBKeVoq3A"; var sheetName = "MySheet1"; // Has to match the sheet name IKeyValueStore onlineNewsStore = new GoogleSheetsKeyValueStore(new InMemoryKeyValueStore(), apiKey, sheetId, sheetName); IKeyValueStore onDeviceEventsStore = new InMemoryKeyValueStore(); IKeyValueStore newsStore = new DualStore(onlineNewsStore, onDeviceEventsStore); var newsLocalDataStore = new InMemoryKeyValueStore().GetTypeAdapter <News.LocalData>(); NewsManager manager = new NewsManager(newsLocalDataStore, newsStore.GetTypeAdapter <News>()); var title = "First App Start"; var descr = "You just started the app the first time!"; var url = "https://github.com/cs-util-com/cscore"; var urlText = "Show details.."; News n = News.NewLocalNewsEvent(title, descr, url, urlText); await onDeviceEventsStore.Set(n.key, n); IEnumerable <News> allNews = await manager.GetAllNews(); Assert.Contains(allNews, x => x.title == title); Log.d(JsonWriter.AsPrettyString(allNews)); IEnumerable <News> unreadNews = await manager.GetAllUnreadNews(); Assert.Contains(unreadNews, x => x.title == title); }
public async Task ExampleUsage1() { // Get your key from https://console.developers.google.com/apis/credentials var exampleApiKey = "AIzaSyCtcFQMgRIUHhSuXggm4BtXT4eZvUrBWN0"; // See https://docs.google.com/spreadsheets/d/1qZjRA_uLsImX-VHpJ1nnrCIASmU20Tbaakf5Le5Wrs8 var spreadsheetId = "1qZjRA_uLsImX-VHpJ1nnrCIASmU20Tbaakf5Le5Wrs8"; var sheetName = "UpdateEntriesV2"; // Has to match the sheet name var cache = new InMemoryKeyValueStore(); var store = new GoogleSheetsKeyValueStore(cache, exampleApiKey, spreadsheetId, sheetName); // Use the GoogleSheets store as the source for the update information: var updateChecker = new DefaultAppUpdateChecker(store, null); var entries = await updateChecker.DownloadAllUpdateEntries(); Assert.Equal(5, entries.Count()); // Use the EnvironmentV2.instance.systemInfo values to match against all entries: var matchingEntries = await updateChecker.DownloadMatchingUpdateEntries(); if (matchingEntries.Count > 0) { Assert.Single(matchingEntries); var instructions = matchingEntries.First().GetUpdateInstructions(); Assert.Equal("https://github.com/cs-util-com/cscore", instructions.url); Log.d("instructions: " + JsonWriter.AsPrettyString(instructions)); } else { Log.e("Test cant be fully done on current system: " + JsonWriter.AsPrettyString(EnvironmentV2.instance.systemInfo)); } }
private static async Task GetLockedAndUnlockedFeatures(IProgressionSystem <FeatureFlag> xpSys, int currentUserXp) { var t = Log.MethodEntered(); { var lockedFeatures = await xpSys.GetLockedFeatures(); var unlockedFeatures = await xpSys.GetUnlockedFeatures(); Assert.NotEmpty(lockedFeatures); Assert.NotEmpty(unlockedFeatures); Assert.Empty(lockedFeatures.Intersect(unlockedFeatures)); // There should be no features in both lists foreach (var feature in lockedFeatures) { Assert.True(currentUserXp < feature.requiredXp); Assert.False(await xpSys.IsFeatureUnlocked(feature)); } foreach (var feature in unlockedFeatures) { Assert.True(currentUserXp >= feature.requiredXp); Assert.True(await xpSys.IsFeatureUnlocked(feature)); } var nextAvailableFeature = lockedFeatures.OrderBy(f => f.requiredXp).First(); Log.d("The next unlocked feature will be " + JsonWriter.AsPrettyString(nextAvailableFeature)); } Log.MethodDone(t); }
public async Task ExampleUsage1() { var searchTerm = "Star Wars"; HashSet <string> all = await GoogleSearchSuggestions.GetAlternativesRecursively(searchTerm); Log.d(JsonWriter.AsPrettyString(all)); }
public void TestJsonToJsonSchema() { string json = JsonWriter.GetWriter().Write(new MyUserModel.UserContact() { phoneNumbers = new int[1] { 123 }, user = new MyUserModel() { name = "Tom", age = 99, phoneNumber = 12345 } }); Log.d("json=" + json); var schemaGenerator = new ModelToJsonSchema(); var schema = schemaGenerator.ToJsonSchema("MyUserModel", json); Log.d(JsonWriter.AsPrettyString(schema)); Assert.Equal("Age", schema.properties["user"].properties["age"].title); Assert.Equal("integer", schema.properties["phoneNumbers"].items.First().type); }
public void TestMultipleJsonWriters2() { // Register a custom writer that handles only MyClass1 conversions: IJsonWriter myClass1JsonConverter = new MyClass1JsonConverter(); IJsonWriter defaultWriter = JsonWriter.GetWriter(this); IoC.inject.RegisterInjector(this, (caller, createIfNull) => { if (caller is MyClass1) { return(myClass1JsonConverter); } return(defaultWriter); // Fallback to default JsonWriter }); // Converting MyClass1 instances to json will now always use the MyClass1JsonConverter: Assert.Equal("[]", JsonWriter.AsPrettyString(new MyClass1())); // Other json conversions still work as usual Assert.Equal("{}", JsonWriter.AsPrettyString(new MyClass2())); // Ensure that the additional create json writer for MyClass2 did not delete MyClass1JsonConverter: Assert.Equal("[]", JsonWriter.AsPrettyString(new MyClass1())); IoC.inject.UnregisterInjector <IJsonWriter>(this); Assert.Equal("{}", JsonWriter.AsPrettyString(new MyClass2())); Assert.NotEqual("[]", JsonWriter.AsPrettyString(new MyClass1())); }
private static async Task GenerateAndShowViewFor(ViewStack viewStack) { { await Dialog.ShowInfoDialog("Generating UIs from C# classes", "The next examples will show generating" + " views from normal C# classes. In this example MyUserModel is passed to the generator", "Show example"); var schemaGenerator = new ModelToJsonSchema(); var userModelType = typeof(MyUserModel); JsonSchema schema = schemaGenerator.ToJsonSchema("" + userModelType, userModelType); Log.d(JsonWriter.AsPrettyString(schema)); await LoadModelIntoGeneratedView(viewStack, schemaGenerator, schema); } { await Dialog.ShowInfoDialog("Generating UIs from JSON schemas", "This time the json schema is loaded from an JSON schema string", "Show example"); var schemaGenerator = new ModelToJsonSchema(); JsonSchema schema = JsonReader.GetReader().Read <JsonSchema>(SomeJsonSchemaExamples.jsonSchema1); await LoadJsonModelIntoGeneratedJsonSchemaView(viewStack, schemaGenerator, schema, SomeJsonSchemaExamples.json1); } { await Dialog.ShowInfoDialog("Editing arrays & lists:", "Both primitave lists but also List<MyClass1> can be shown and edited", "Show list example"); var schemaGenerator = new ModelToJsonSchema(); JsonSchema schema = JsonReader.GetReader().Read <JsonSchema>(SomeJsonSchemaExamples.jsonSchema2); await LoadJsonModelIntoGeneratedJsonSchemaView(viewStack, schemaGenerator, schema, SomeJsonSchemaExamples.json2); } }
public async Task TestEventListeners() { using (ProgressV2 progress = new ProgressV2("p3", 200)) { var progressEventTriggered = false; progress.ProgressChanged += (o, newValue) => { Log.e(JsonWriter.AsPrettyString(o)); Assert.Equal(100, newValue); progressEventTriggered = true; }; await TaskV2.Run(() => { ((IProgress <double>)progress).Report(100); Assert.False(progressEventTriggered); Assert.Equal(100, progress.GetCount()); Assert.Equal(50, progress.percent); }); Assert.Equal(100, progress.GetCount()); Assert.Equal(50, progress.percent); // The progress callback is dispatched using the SynchronizationContext // of the constructor, so it will have some delay before being called: Assert.False(progressEventTriggered); await TaskV2.Delay(50); // Wait for progress update to be invoked Assert.True(progressEventTriggered); } }
public async Task TestPostFormData() { // Use postman-echo.com to test posting form data including files: RestRequest request = new Uri("https://postman-echo.com/post").SendPOST(); DirectoryEntry dir = EnvironmentV2.instance.GetNewInMemorySystem(); FileEntry fileToUpload = dir.GetChild("test.txt"); fileToUpload.SaveAsText("I am a text"); request.AddFileViaForm(fileToUpload); string formText = "I am a string"; request.WithFormContent(new Dictionary <string, object>() { { "formString1", formText } }); PostmanEchoResponse result = await request.GetResult <PostmanEchoResponse>(); Log.d(JsonWriter.AsPrettyString(result)); Assert.Single(result.form); Assert.Equal(formText, result.form.First().Value); Assert.Single(result.files); Assert.Equal(fileToUpload.Name, result.files.First().Key); }
public async Task TestFileIoUpload() { DirectoryEntry dir = EnvironmentV2.instance.GetNewInMemorySystem(); FileEntry fileToUpload = dir.GetChild("test.txt"); string textInFile = "I am a text"; fileToUpload.SaveAsText(textInFile); Assert.Equal(textInFile, fileToUpload.LoadAs <string>()); RestRequest uploadRequest = new Uri("https://file.io/?expires=1d").SendPOST().AddFileViaForm(fileToUpload); uploadRequest.WithRequestHeaderUserAgent("" + GuidV2.NewGuid()); FileIoResponse result = await uploadRequest.GetResult <FileIoResponse>(); Log.d(JsonWriter.AsPrettyString(result)); Assert.True(result.success); Assert.NotEmpty(result.link); FileEntry fileToDownloadTo = dir.GetChild("test2.txt"); var downloadRequest = new Uri(result.link).SendGET(); downloadRequest.WithRequestHeaderUserAgent("" + GuidV2.NewGuid()); await downloadRequest.DownloadTo(fileToDownloadTo); //Assert.True(textInFile == fileToDownloadTo.LoadAs<string>(), "Invalid textInFile from " + result.link); Assert.Equal(textInFile, fileToDownloadTo.LoadAs <string>()); }
protected override async Task <bool> SendEventToExternalSystem(AppFlowEvent appFlowEvent) { Log.d("SendEventToExternalSystem called with appFlowEvent=" + JsonWriter.AsPrettyString(appFlowEvent)); await TaskV2.Delay(10); // Simulate that sending the event to an analytics server takes time eventsThatWereSent.Add(appFlowEvent); return(true); }
public void TestNameSpace() { var assembly = typeof(Log).Assembly; Log.d(JsonWriter.AsPrettyString(assembly.GetAllNamespaces())); var typesWithMissingNamespace = assembly.GetTypesWithMissingNamespace(); Assert.Empty(typesWithMissingNamespace); }
private static void AssertActionDidNotChangeDuringDispatch(object actionBeforeDispatch, object actionAfter) { if (HasDiff(actionBeforeDispatch, actionAfter, out JToken diff)) { Log.e($"The action {actionAfter.GetType()} was changed by dispatching it, check reducers: " + "\n Diff: " + diff.ToPrettyString() + "\n\n Action before dispatch: " + JsonWriter.AsPrettyString(actionBeforeDispatch) + "\n\n Action after dispatch: " + JsonWriter.AsPrettyString(actionAfter) ); } }
public void TestLogSystemAttributes() { var sysInfo = EnvironmentV2.instance.systemInfo; Log.d("SysInfos: " + JsonWriter.AsPrettyString(sysInfo)); var c = TimeZoneInfo.Local.GetUtcOffset(DateTimeV2.UtcNow); Log.d("TimeZoneInfo.Local.GetUtcOffset(DateTimeV2.UtcNow): " + JsonWriter.AsPrettyString(c)); var si2 = CloneHelper.DeepCopyViaJson(sysInfo); Assert.Equal(JsonWriter.AsPrettyString(sysInfo), JsonWriter.AsPrettyString(si2)); }
private void ShowFormCompletedDebugInfos(ForkedStore <MyDataModel> fork) { Snackbar.Show($"The {fork.recordedActions.Count} changes to the user are now saved", "Show details", delegate { LogConsole.GetLogConsole(this).ClearConsole(); LogConsole.GetLogConsole(this).ShowConsole(true); foreach (var a in fork.recordedActions) { Log.d(JsonWriter.AsPrettyString(a)); } }); }
public async Task TestSendTimingToGA() { var googleAnalytics = new GoogleAnalytics(TEST_APP_KEY, NewInMemoryStore()) { url = GoogleAnalytics.DEBUG_ENDPOINT // Use the debug endpoint }; // Test if the GA debug endpoint is returning that the request is valid: var t = googleAnalytics.NewTiming("cat1", "var1", timingInMs: 22); var res = await googleAnalytics.SendToGA(t).GetResult <GoogleAnalyticsDebugResp>(); Log.d(JsonWriter.AsPrettyString(res)); Assert.True(res.hitParsingResult.First().valid, JsonWriter.AsPrettyString(res)); }
public async Task TestConvertEventToQueryParams() { var googleAnalytics = new GoogleAnalytics(TEST_APP_KEY, NewInMemoryStore()) { url = GoogleAnalytics.DEBUG_ENDPOINT // Use the debug endpoint }; var e = googleAnalytics.NewEvent("cat1", "action1", "label1", value: 123); var queryParams = RestRequestHelper.ToUriEncodedString(e); var fullUrl = googleAnalytics.url + "?" + queryParams; var res = await new Uri(fullUrl).SendGET().GetResult <GoogleAnalyticsDebugResp>(); Assert.True(res.hitParsingResult.First().valid, JsonWriter.AsPrettyString(res)); }
public async Task TestSendEventToGA() { var googleAnalytics = new GoogleAnalytics(TEST_APP_KEY, new InMemoryKeyValueStore()) { url = GoogleAnalytics.DEBUG_ENDPOINT // Use the debug endpoint }; // Test if the GA debug endpoint is returning that the request is valid: var e = googleAnalytics.NewEvent("cat1", "action1", "label1", value: 123); var res = await googleAnalytics.SendToGA(e).GetResult <GoogleAnalyticsDebugResp>(); Log.d(JsonWriter.AsPrettyString(res)); Assert.True(res.hitParsingResult.First().valid, JsonWriter.AsPrettyString(res)); }
public void TestNameSpace() { var assembly = typeof(Log).Assembly; Log.d(JsonWriter.AsPrettyString(assembly.GetAllNamespaces())); var typesWithMissingNamespace = assembly.GetTypesWithMissingNamespace(); if (typesWithMissingNamespace.Count() == 0) { throw new Exception("These types have missing namespaces:" + typesWithMissingNamespace.ToStringV2()); } }
public void TestEnum() { var schema = new ModelToJsonSchema().ToJsonSchema("FromClassType", typeof(UserStats)); var e1 = schema.properties["experience1"]; var e2 = schema.properties["experience2"]; var e3 = schema.properties["experience3"]; var e4 = schema.properties["experience4"]; var e5 = schema.properties["experience5"]; Log.d(JsonWriter.AsPrettyString(schema)); Assert.Equal(Enum.GetNames(typeof(UserStats.Experience)), e1.contentEnum); Assert.Equal(e1.contentEnum, e2.contentEnum); Assert.Equal(e2.contentEnum, e3.contentEnum); Assert.Equal(e3.contentEnum, e4.contentEnum); Assert.Equal(e4.contentEnum, e5.contentEnum); }
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()); } }
public async Task MetaWeatherComExample1() { var ipLookupResult = await IpApiCom.GetResponse(); string yourCity = ipLookupResult.city; var cityLookupResult = await MetaWeatherLocationLookup.GetLocation(yourCity); if (cityLookupResult.IsNullOrEmpty()) { cityLookupResult = await MetaWeatherLocationLookup.GetLocation((float)ipLookupResult.lat, (float)ipLookupResult.lon); } Assert.False(cityLookupResult.IsNullOrEmpty(), "Did not find any location for city=" + yourCity); int whereOnEarthIDOfYourCity = cityLookupResult.First().woeid; var report = await MetaWeatherReport.GetReport(whereOnEarthIDOfYourCity); Log.d("Full weather report: " + JsonWriter.AsPrettyString(report)); var currentWeather = report.consolidated_weather.Map(r => r.weather_state_name); Log.d("The weather today in " + yourCity + " is: " + currentWeather.ToStringV2()); }
public static bool AddToProjectViaPackageManager(string packageName, string packageVersion) { var manifestFile = EditorIO.GetProjectFolder().GetChildDir("Packages").GetChild("manifest.json"); if (manifestFile.IsNotNullAndExists()) { var manifest = manifestFile.LoadAs <Dictionary <string, object> >(); JObject dependencies = (manifest["dependencies"] as JObject); if (dependencies != null) { if (dependencies.TryGetValue(packageName, out JToken foundVersion)) { if (packageVersion.Equals(foundVersion.ToObject <string>())) { // Log.d("Package " + packageName + " already contained in Packages/manifest.json"); return(true); } else { Log.w("Package " + packageName + ":" + packageVersion + " not added, found exist. version in manifest.json: " + foundVersion); } } else { var s = JsonSerializer.Create(JsonNetSettings.defaultSettings); dependencies.Add(packageName, JToken.FromObject(packageVersion, s)); manifestFile.SaveAsText(JsonWriter.AsPrettyString(manifest)); return(true); } } else { Log.e("Dependencies list not found in manifest.json"); } } else { Log.e("Manifest.json file not found at " + manifestFile); } return(false); }
public async Task TestImageFileRef() { var dir = EnvironmentV2.instance.GetOrAddTempFolder("TestImageFileWithThumbnail"); var imgRef = new FileRef() { url = "https://picsum.photos/1024/512" }; await imgRef.DownloadTo(dir); Log.d("FileRef: " + JsonWriter.AsPrettyString(imgRef)); Assert.NotNull(imgRef.url); Assert.NotNull(imgRef.fileName); Assert.NotNull(imgRef.dir); FileEntry imgEntry = imgRef.GetFileEntry(dir.FileSystem); var img = await ImageLoader.LoadImageInBackground(imgEntry); Assert.Equal(1024, img.Width); Assert.Equal(512, img.Height); }
public static async Task <object> Set(this IKeyValueStore self, string key, object newValue, object oldValue) { if (self != null) { var storeOldValue = await self.Set(key, newValue); if (storeOldValue != null) { if (oldValue == null) { oldValue = storeOldValue; } if (storeOldValue != oldValue) { AssertV2.IsTrue(JsonWriter.HasEqualJson(storeOldValue, oldValue), "oldValue != store.oldValue, store value newer?" + "\n storeOldValue=" + JsonWriter.AsPrettyString(storeOldValue) + "\n oldValue=" + JsonWriter.AsPrettyString(oldValue)); } } } return(oldValue); }
public async Task TestPostFormData2() { // Use postman-echo.com to test posting form data including files: RestRequest request = new Uri("https://postman-echo.com/post").SendPOST(); string formText1 = "I am a string 1"; string formText2 = "I am a string 2"; var formData = new Dictionary <string, object>(); formData.Add("formString1", formText1); formData.Add("formString2", formText2); request.WithFormContent(formData); PostmanEchoResponse result = await request.GetResult <PostmanEchoResponse>(); Log.d(JsonWriter.AsPrettyString(result)); Assert.Equal(2, result.form.Count); Assert.Equal(formText1, result.form.First().Value); Assert.Equal(formText2, result.form.Skip(1).First().Value); Assert.Equal("application/x-www-form-urlencoded", result.headers.contentType); }
public static bool AddToProjectViaPackageManager(string packageName, string packageVersion) { var manifestFile = EnvironmentV2.instance.GetCurrentDirectory().Parent.GetChildDir("Packages").GetChild("manifest.json"); if (manifestFile.IsNotNullAndExists()) { var manifest = manifestFile.LoadAs <Dictionary <string, object> >(); JObject dependencies = (manifest["dependencies"] as JObject); if (dependencies != null) { if (dependencies.TryGetValue(packageName, out JToken foundVersion)) { if (packageVersion.Equals(foundVersion.ToObject <string>())) { // Log.d("Package " + packageName + " already contained in Packages/manifest.json"); return(true); } else { Log.w("Package " + packageName + ":" + packageVersion + " not added, found exist. version in manifest.json: " + foundVersion); } } else { dependencies.Add(packageName, JToken.FromObject(packageVersion)); manifestFile.SaveAsText(JsonWriter.AsPrettyString(manifest)); return(true); } } else { Log.e("Dependencies list not found in manifest.json"); } } else { Log.e("Manifest.json file not found at " + manifestFile.FullPath()); } return(false); }
public Task OnLoad(MyModel model) { var map = targetView.GetLinkMap(); tripStartInput = map.Get <InputField>("TripStartInput"); tripBackInput = map.Get <InputField>("TripBackInput"); oneWayDropdown = map.Get <Dropdown>("OneWayDropdown"); bookButton = map.Get <Button>("BookButton"); tripStartInput.text = "" + model.tripStart; tripStartInput.AddOnValueChangedActionThrottled(newVal => { if (ShowValidInUi(tripStartInput, DateTime.TryParse(newVal, out DateTime d))) { model.tripStart = d; UpdateUi(model); } }, delayInMs: 1000); tripBackInput.AddOnValueChangedActionThrottled(newVal => { if (ShowValidInUi(tripBackInput, DateTime.TryParse(newVal, out DateTime d))) { model.tripBack = d; UpdateUi(model); } }, delayInMs: 1000); oneWayDropdown.SetOnValueChangedAction(selectedEntry => { model.flightType = IsTwoWaySelected() ? MyModel.FlightType.withReturnFlight : MyModel.FlightType.oneWayFlight; // Auto fill the trip back the first time its selected: if (IsTwoWaySelected() && model.tripBack == null) { model.tripBack = model.tripStart + TimeSpan.FromDays(1); tripBackInput.text = "" + model.tripBack; } UpdateUi(model); return(true); }); UpdateUi(model); return(bookButton.SetOnClickAction(delegate { Toast.Show("Flight now booked: " + JsonWriter.AsPrettyString(model)); })); }
public async Task ExampleUsage2() { // Get your key from https://console.developers.google.com/apis/credentials var apiKey = "AIzaSyCtcFQMgRIUHhSuXggm4BtXT4eZvUrBWN0"; // https://docs.google.com/spreadsheets/d/1rl1vi-LUhOgoY_QrMJsm2UE0SdiL4EbOtLwfNPsavxQ contains the sheetId: var sheetId = "1rl1vi-LUhOgoY_QrMJsm2UE0SdiL4EbOtLwfNPsavxQ"; var sheetName = "UsageRules1"; // Has to match the sheet name var source = new GoogleSheetsKeyValueStore(new InMemoryKeyValueStore(), apiKey, sheetId, sheetName); var store = source.GetTypeAdapter <UsageRule>(); var analytics = CreateLocalAnalyticsSystem(); IEnumerable <UsageRule> rules = await store.GetRulesInitialized(analytics); foreach (var rule in rules) { if (await rule.isTrue()) { Log.d(JsonWriter.AsPrettyString(rule)); // TODO } } Assert.Single(rules.Filter(r => !r.andRules.IsNullOrEmpty())); }