private static void ResolveViewModelName(MemberDefinition member, ViewModelSettings viewModel, RenderSettings settings) { var namespaces = member.Dependencies(); // if we don't have specific namespaces to search, we search them all if (namespaces == null || namespaces.Length == 0) { namespaces = settings.namespaces.Select(n => n.Key).ToArray(); } foreach (var ns in namespaces) { var vms = FindViewModelSettingsInNamespace(ns, member.PropertyType(), settings); if (vms != null) { // we are using the discovered view model's namespace viewModel.usings.Add(vms.ViewModelNamespace()); if (member is CollectionDefinition) { (member as CollectionDefinition).typeParam = vms.type; } else { (member as PropertyDefinition).type = vms.type; } return; // success - we stop right here } } // if we get here, a view model was never found, so we are not emitting as view model member.EmitAsViewModel(false); }
private static void BuildViewModelSettingsForEntity(Type entity, RenderSettings settings, List <Type> allEntities) { var attr = entity.GetCustomAttribute <ViewModelAttribute>(); var vms = new ViewModelSettings(); vms.EntityType(entity.Name); vms.EntityNamespace(entity.Namespace); vms.HasPublicEntity(entity.IsPublic); if (attr != null) { ApplyViewModelAttribute(vms, attr); } // add or update the view model on its namespace settings SettingsBuilder.IncludeViewModelSettings(settings, vms); // find and build view model rendering settings for all relevant properties in the entity var props = DiscoverViewModelProperties(vms, entity); foreach (var p in props) { ConfigureViewModelProperty(p, vms, allEntities); } }
public MaterialEditViewModel(Model.MaterialModel materialModel, ViewModelSettings viewModelSettings) : base(materialModel, viewModelSettings) { Name = this.EntityViewModel.Name; FileName = this.EntityViewModel.FileName; Body = this.EntityViewModel.Body; SelectFileCommand = new Command(SelectFile); OpenFileCommand = new Command(() => MaterialViewModel.OpenFile(FileName, Body)); }
/// <summary> /// Checks the web request result for any errors, displaying them if there are any, /// or if we are unauthorized automatically logging us out /// </summary> /// <typeparam name="T">The type of Api Response</typeparam> /// <param name="response">The response to check</param> /// <param name="title">The title of the error dialog if there is an error</param> /// <returns>Returns true if there was an error, or false if all was OK</returns> public static async Task <bool> HandleErrorIfFailedAsync(this WebRequestResult response, string title) { // If there was no response, bad data, or a response with a error message... if (response == null || response.ServerResponse == null || (response.ServerResponse as ApiResponse)?.Successful == false) { // Default error message // TODO: Localize strings var message = "Unknown error from server call"; // If we got a response from the server... if (response?.ServerResponse is ApiResponse apiResponse) { // Set message to servers response message = apiResponse.ErrorMessage; } // If we have a result but deserialize failed... else if (!string.IsNullOrWhiteSpace(response?.RawServerResponse)) { // Set error message message = $"Unexpected response from server. {response.RawServerResponse}"; } // If we have a result but no server response details at all... else if (response != null) { // Set message to standard HTTP server response details message = response.ErrorMessage ?? $"Server responded with {response.StatusDescription} ({response.StatusCode})"; } // If this is an unauthorized response... if (response?.StatusCode == System.Net.HttpStatusCode.Unauthorized) { // Log it Logger.LogInformationSource("Logging user out due to unauthorized response from server"); // Automatically log the user out await ViewModelSettings.LogoutAsync(); } else { // Display error await UI.ShowMessage(new MessageBoxDialogViewModel { // TODO: Localize strings Title = title, Message = message }); } // Return that we had an error return(true); } // All was OK, so return false for no error return(false); }
public override IEnumerable <MaterialTypeViewModel> GetItems(ViewModelSettings viewModelSettings) { if (DefaultSpecification == null) { return(new MaterialTypeViewModel[0]); } else { return(base.GetItems(viewModelSettings)); } }
/// <summary> /// Конструктор для добавления /// </summary> public BaseEditViewModel(AModel <TEntity, TEntityViewModel> entityModel, ViewModelSettings viewModelSettings) { ViewModelSettings = viewModelSettings; EntityModel = entityModel; Mode = EMode.Add; ContinueButtonName = "Добавить"; var entity = Activator.CreateInstance <TEntity>(); EntityViewModel = Activator.CreateInstance(typeof(TEntityViewModel), new object[] { entity, ViewModelSettings }) as TEntityViewModel; Initialize(Add); }
private static void ConfigureEntityProperty(PropertyInfo propInfo, ViewModelSettings vm, List <Type> entities, MemberDefinition propDef) { var doNotEmitAsViewModel = propInfo.GetCustomAttribute <DoNotEmitAsViewModelAttribute>() != null; var emitAsViewModel = propInfo.GetCustomAttribute <EmitAsViewModelAttribute>() != null; var prop = propDef as PropertyDefinition; // if not explicitly restricted from emitting this as a view model, // and we are implicitly emitting entity properties as view models or there is a explicit // instruction to emit this property as a view model, make it so propDef.EmitAsViewModel(doNotEmitAsViewModel == false && (vm.emitEntityPropertiesAsViewModels == true || emitAsViewModel == true) && entities.Any(e => e.Name == prop.type)); }
/// <summary> /// Handles what happens when we have successfully logged in /// </summary> /// <param name="loginResult">The results from the successful login</param> public async Task HandleSuccessfulLoginAsync(UserProfileDetailsApiModel loginResult) { // Store this in the client data store await ClientDataStore.SaveLoginCredentialsAsync(loginResult.ToLoginCredentialsDataModel()); //Show Login Details LoginDetailsVisible = true; // Load new settings await ViewModelSettings.LoadAsync(); // Go to home page ViewModelApplication.GoToPage(ApplicationPage.Home); }
/// <summary> /// Configures our application ready for use /// </summary> private async Task ApplicationSetupAsync() { // Setup the Dna Framework Framework.Construct <DefaultFrameworkConstruction>() .AddFileLogger() .AddClientDataStore() .AddFasettoWordViewModels() .AddFasettoWordClientServices() .Build(); // Ensure the client data store await ClientDataStore.EnsureDataStoreAsync(); // Load new settings await ViewModelSettings.LoadAsync(); }
private static void ApplyViewModelAttribute(ViewModelSettings vm, ViewModelAttribute attr) { vm.access = attr.AccessModifier; vm.emitAllProperties = attr.EmitAllProperties; vm.emitCollectionsAsObservable = attr.EmitCollectionsAsObservable; vm.emitEntityPropertiesAsViewModels = attr.EmitEntityPropertiesAsViewModels; vm.emitTo = attr.EmitToDir; vm.inheritUsings = attr.InheritUsings; vm.partialClass = attr.PartialClass; vm.stubForCustomCode = attr.CreateStubForCustomCode; vm.type = attr.ViewModelType; foreach (var u in attr.Usings) { vm.usings.Add(u); } }
public Settings() { InitializeComponent(); _viewModel = App.ViewModelSettings; MidataSwitch.IsVisible = true; ToolbarItems.Add(new ToolbarItem(Multilanguage.TranslateExtension.getString("SaveSettings"), "", () => { var saveSettings = ViewModelSettings.SmaNaSettings; Schema schema; SchemaDictionary.TryGetValue(SettingsSchema.Items[SettingsSchema.SelectedIndex], out schema); saveSettings.Schema = schema.filename; saveSettings.OperationDate = OperationDate.Date; saveSettings.StageingComplete = StageingComplete.IsToggled; var languageChanged = false; if (saveSettings.LanguageString != Language.Items[Language.SelectedIndex]) { CultureInfo ci; LanguageDictionary.TryGetValue(Language.Items[Language.SelectedIndex], out ci); saveSettings.Language = ci; languageChanged = true; } _viewModel.SaveSettings(); if (languageChanged) { App.SetCulture(saveSettings.Language); } //await Navigation.PopAsync(); })); InitializeDropdowns(); var settings = ViewModelSettings.SmaNaSettings; SettingsSchema.SelectedIndex = SettingsSchema.Items.IndexOf(SchemaDictionary.FirstOrDefault(x => x.Value.filename == settings.Schema).Key); if (SettingsSchema.SelectedIndex == -1) { SettingsSchema.SelectedIndex = 0; } Language.SelectedIndex = Language.Items.IndexOf(LanguageDictionary.FirstOrDefault(x => x.Value.Name == settings.LanguageString).Key); OperationDate.Date = settings.OperationDate; StageingComplete.IsToggled = settings.StageingComplete; MiData.IsToggled = false; MidataLayout.IsVisible = false; }
/// <summary> /// Handles what happens when we have successfully logged in /// </summary> /// <param name="loginResult">The results from the successful login</param> public async Task HandleSuccessfulLoginAsync(LoginResultApiModel loginResult) { // Store this in the client data store await ClientDataStore.SaveLoginCredentialsAsync(new LoginCredentialsDataModel { Email = loginResult.Email, FirstName = loginResult.FirstName, LastName = loginResult.LastName, Username = loginResult.Username, Token = loginResult.Token }); // Load new settings await ViewModelSettings.LoadAsync(); // Go to chat page ViewModelApplication.GoToPage(ApplicationPage.Chat); }
private static void ConfigureViewModelProperty(PropertyInfo propInfo, ViewModelSettings vm, List <Type> entities) { MemberDefinition propDef; if (PropertyInfoParser.IsPropertyIList(propInfo)) { propDef = PropertyInfoParser.BuildCollectionDefinition(propInfo); } else { propDef = PropertyInfoParser.BuildPropertyDefinition(propInfo); } var attr = propInfo.GetCustomAttribute <ViewModelPropertyAttribute>(); if (attr != null) { ApplyViewModelPropertyAttribute(propDef, attr); } // submit namespaces used by this property as usings var deps = propDef.Dependencies(); foreach (var ns in deps) { vm.usings.Add(ns); } // collections if (propDef is CollectionDefinition) { ConfigureCollectionProperty(propInfo, vm, entities, propDef); } // entities else if (entities.Any(e => e.Name == propDef.PropertyType())) { ConfigureEntityProperty(propInfo, vm, entities, propDef); } // add or update this member on its view model settings SettingsBuilder.IncludeMemberDefinition(propDef, vm); }
private static List <PropertyInfo> DiscoverViewModelProperties(ViewModelSettings vm, Type entity) { List <PropertyInfo> properties = null; if (vm.emitAllProperties == true) { properties = entity.GetProperties() .Where(p => p.GetCustomAttribute <NotViewModelPropertyAttribute>() == null) .ToList(); } else { properties = entity.GetProperties() .Where(p => p.GetCustomAttribute <ViewModelPropertyAttribute>() != null && p.GetCustomAttribute <NotViewModelPropertyAttribute>() == null) .ToList(); } return(properties); }
private ViewModelBase CreateViewModel <T>() where T : UserControl { Type type = typeof(T); ViewModelBase vm = null; if (type == typeof(UserControlAbout)) { vm = new ViewModelAbout(); } else if (type == typeof(UserControlSettings)) { vm = new ViewModelSettings(); } else { DBG_Stop(); } return(vm); }
private AItemViewModel(ViewModelSettings viewModelSettings) { ViewModelSettings = viewModelSettings; PreInitialization(); ItemDoubleClickCommand = new Command(() => {//чтобы можно было динамически менять параметры if (ViewModelSettings.AllowDoubleClick) { if (ViewModelSettings.ElementDoubleClick != null) { ViewModelSettings.ElementDoubleClick(this.Entity); } else { DoubleClickedInner(); } } }); }
private static void ConfigureCollectionProperty(PropertyInfo propInfo, ViewModelSettings vm, List <Type> entities, MemberDefinition propDef) { var doNotEmitAsObservable = propInfo.GetCustomAttribute <DoNotEmitAsObservableAttribute>() != null; var emitAsObservable = propInfo.GetCustomAttribute <EmitAsObservableAttribute>(); // if not explicitly restricted from emitting this an observable, // and we are implicitly making collections observable or there is a explicit // designation of this property as observable, make it so if (doNotEmitAsObservable == false && (vm.emitCollectionsAsObservable == true || emitAsObservable != null)) { var coll = propDef as CollectionDefinition; coll.collectionType = "ObservableCollectionPlus"; // determine whether or not to emit this collection's type parameter // as a view model. This is something we'll need to do later on, // once we have all of our view model settings in place, as we'll // need to do a lookup on these settings to get the view model name coll.EmitAsViewModel( emitAsObservable?.EmitTypeParamAsViewModel == true && entities.Any(e => e.Name == coll.typeParam)); } }
public MaterialTypeEditViewModel(Model.MaterialTypeModel materialTypeModel, ViewModelSettings viewModelSettings) : base(materialTypeModel, viewModelSettings) { Name = EntityViewModel.Name; }
public Settings(MainWindow parent) { this.parent = parent; settingsVM = new ViewModelSettings(parent.viewModel); InitializeComponent(); }
public DisciplineEditViewModel(Model.DisciplineModel disciplineModel, ViewModelSettings viewModelSettings) : base(disciplineModel, viewModelSettings) { }
public LinkChild() { ViewModelSettings = new ViewModelSettings(); GotoLinkCommand = new Command(GotoLink); }
/// <summary> /// Получить список сущностей /// </summary> /// <param name="viewModelSettings"></param> /// <returns></returns> public virtual IEnumerable <TEntityViewModel> GetItems(ViewModelSettings viewModelSettings) { var result = _repository.Find(DefaultSpecification); return(result.Select(x => Activator.CreateInstance(typeof(TEntityViewModel), new object[] { x, viewModelSettings }) as TEntityViewModel).ToArray()); }
public AItemViewModel(TEntity entity, ViewModelSettings viewModelSettings) : this(viewModelSettings) { Entity = entity; }