public override void Initialize() { services = Services.Create(); grain = services.GetRequiredService <IStateFactory>().GetAsync <MyAppState, AppStateGrainState>("DEFAULT").Result; var state = new AppStateGrainState { App = new JsonAppEntity { Id = Guid.NewGuid() } }; state.Schemas = ImmutableDictionary <Guid, JsonSchemaEntity> .Empty; for (var i = 1; i <= 100; i++) { var schema = new JsonSchemaEntity { Id = Guid.NewGuid(), Created = SystemClock.Instance.GetCurrentInstant(), CreatedBy = new RefToken("user", "1"), LastModified = SystemClock.Instance.GetCurrentInstant(), LastModifiedBy = new RefToken("user", "1"), SchemaDef = new Schema("Name") }; for (var j = 1; j < 30; j++) { schema.SchemaDef = schema.SchemaDef.AddField(new StringField(j, j.ToString(), Partitioning.Invariant)); } state.Schemas = state.Schemas.Add(schema.Id, schema); } state.Rules = ImmutableDictionary <Guid, JsonRuleEntity> .Empty; for (var i = 0; i < 100; i++) { var rule = new JsonRuleEntity { Id = Guid.NewGuid(), Created = SystemClock.Instance.GetCurrentInstant(), CreatedBy = new RefToken("user", "1"), LastModified = SystemClock.Instance.GetCurrentInstant(), LastModifiedBy = new RefToken("user", "1"), RuleDef = new Rule(new ContentChangedTrigger(), new WebhookAction()) }; state.Rules = state.Rules.Add(rule.Id, rule); } grain.SetState(state); grain.WriteStateAsync().Wait(); }
public static async Task SaveAppSettingsToDB(MyAppState myAppStateIn) { string str = Serialize(myAppStateIn); Settings settings = new Settings { Id = 1, strSettings = str, }; await App.SettingsDB.UpdateSettingsAsync(settings); }
public static MyAppState SetDefaultAppSettings() { Debug.WriteLine("In SetDefaultAppSettings"); MyAppState myAppState = new MyAppState(); myAppState.AppSettingsVersion = null; myAppState.EmailAddress = "*****@*****.**"; myAppState.AdvtsConsented = false; myAppState.CutoffDate = Convert.ToDateTime("1/1/2000"); myAppState.SelectedSize = "Large"; myAppState.EventsDeleteThreshold = 3; myAppState.MaxDiscountPct = 5; return(myAppState); } // end of: SetDefaultAppSettings()
private static async Task <MyAppState> ReadObjectAsync(string filename) { Debug.WriteLine("In ReadObjectAsync"); MyAppState myAppState = null; if (await FileHelper.ExistsAsync(filename)) { string str = await FileHelper.ReadTextAsync(filename); Debug.WriteLine($"Read from file - str ({str.Length}): {str}"); myAppState = Deserialize <MyAppState>(str); } return(myAppState); }
private static async Task <MyAppState> ReadTableAsync() { MyAppState myAppState = null; Settings settings = await App.SettingsDB.GetSettingsAsync(1); if (settings != null) { myAppState = Deserialize <MyAppState>(settings.strSettings); } //List<Settings> settingsList = await App.SettingsDB.GetSettingsAsync(1); //if (settingsList != null && settingsList.Count > 0) // myAppState = Deserialize<MyAppState>(settingsList[0].strSettings); return(myAppState); }
} // end of: SetDefaultAppSettings() #region SQLite DB Table public static async Task <MyAppState> LoadAppSettingsFromDB() { MyAppState myAppState = await ReadTableAsync(); if (myAppState == null) { // Set default settings MyAppState tState = SetDefaultAppSettings(); // Save default settings await App.SettingsDB.Add2SettingsAsync(Serialize(tState)); // Read the saved default settings myAppState = await ReadTableAsync(); } return(myAppState); }
private void LoadAppState(MyAppState prevAppState) { var argFilename = (string)Application.Current.Resources[Constants.Resources.Arg1Key]; if (TryToLoadXshdFile(argFilename)) { appStateService.SaveAppState_FilenameXshd(argFilename); } else if (TryToLoadXshdFile(prevAppState.LastFilenameXshd)) { } if (prevAppState.LastFilenameSample != null && File.Exists(prevAppState.LastFilenameSample)) { CodeDocumentSample.Text = File.ReadAllText(prevAppState.LastFilenameSample); CodeDocumentSample.UndoStack.ClearAll(); } _CmdUser_TriggerBuild(); }
public static async Task <MyAppState> LoadAppSettingsFromFile() { Debug.WriteLine("In LoadAppSettingsFromFile"); MyAppState myAppState = await ReadObjectAsync(App.APP_SETTINGS_KEY); if (myAppState == null) { Debug.WriteLine("App Settings not exist - setting defaults"); // Set default settings MyAppState tState = SetDefaultAppSettings(); // Save default settings await SaveAppSettingsToFile(tState); // Read the saved default settings myAppState = await ReadObjectAsync(App.APP_SETTINGS_KEY); } return(myAppState); }
public static MyAppState LoadAppSettingsFromXEPrefs() { MyAppState myAppState = null; string s = Preferences.Get(App.APP_SETTINGS_KEY, null); if (s != null) { myAppState = GetObject <MyAppState>(App.APP_SETTINGS_KEY); } if (myAppState == null) { // Set default settings MyAppState tState = SetDefaultAppSettings(); // Save default settings SaveAppSettingsToXEPrefs(tState); // Read the saved default settings myAppState = GetObject <MyAppState>(App.APP_SETTINGS_KEY); } return(myAppState); }
public static void SaveAppSettingsToXEPrefs(MyAppState myAppStateIn) { SaveObject(App.APP_SETTINGS_KEY, myAppStateIn); }
public static async Task SaveAppSettingsToFile(MyAppState myAppStateIn) { Debug.WriteLine("In SaveAppSettingsToFile"); await SaveObjectAsync(App.APP_SETTINGS_KEY, myAppStateIn); }