public void Initialize() { VMController.Register("HelloWorldRuntimeVM", _ => { var vm = new BaseVM(); var firstName = vm.AddProperty("FirstName", "Hello"); var lastName = vm.AddProperty("LastName", "World"); vm.AddProperty <string>("FullName").SubscribeTo(Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}")); return(vm); }); VMController.Register("MyNamespace.HelloWorldRuntimeVM", _ => { var vm = new BaseVM(); var firstName = vm.AddProperty("FirstName", "John"); var lastName = vm.AddProperty("LastName", "Hancock"); vm.AddProperty <string>("FullName").SubscribeTo(Observable.CombineLatest(firstName, lastName, (fn, ln) => $"{fn} {ln}")); return(vm); }); var hubEmulatorBuilder = new HubEmulatorBuilder(); foreach (var typeHelper in VMController.VMTypes) { hubEmulatorBuilder.Register(typeHelper.FullName, typeHelper.CreateInstance()); } _hubEmulator = hubEmulatorBuilder.Build(); }
/// <summary> /// When a new widget is added, check whether it's a Calendar widget or calendar listener widgets and /// establish communication between them through the Observer pattern. /// </summary> private void OnNewWidget(BaseVM iWidgetVM) { if (iWidgetVM is ICalendarListener) { var calendar = _WidgetVMs.FirstOrDefault(i => i is ICalendar) as ICalendar; if (calendar != null) { var listener = iWidgetVM as ICalendarListener; calendar.DateChanged += listener.OnDateChanged; calendar.MonthChanged += listener.OnMonthChanged; listener.Init(calendar.SelectedDate, calendar.CurrentMonth); } } else if (iWidgetVM is ICalendar) { var calendar = iWidgetVM as ICalendar; foreach (ICalendarListener listener in _WidgetVMs.Where(i => i is ICalendarListener)) { calendar.DateChanged += listener.OnDateChanged; calendar.MonthChanged += listener.OnMonthChanged; listener.Init(calendar.SelectedDate, calendar.CurrentMonth); } } iWidgetVM.Disposed += (sender, e) => _WidgetVMs.Remove(iWidgetVM); _WidgetVMs.Add(iWidgetVM); }
public IActionResult Photos() { BaseVM mdl = new BaseVM(); mdl = UserToMdl(mdl); return(View(mdl)); }
public override void Process(TagHelperContext context, TagHelperOutput output) { BaseVM vm = null; if (context.Items.TryGetValue("model", out object baseVM)) { vm = baseVM as BaseVM; } else { //TODO 若 image 组件未在form中该如何解决 _DONOT_USE_CS 的问题? } if (string.IsNullOrEmpty(Url) && Field.Model != null) { Url = $"/_Framework/GetFile/{Field.Model}"; if (vm != null) { Url = Url.AppendQuery($"_DONOT_USE_CS={vm.CurrentCS}"); } } output.TagName = "img"; output.TagMode = TagMode.SelfClosing; output.Attributes.Add("name", Field.Name + "img"); output.Attributes.Add("id", Id + "img"); if (!string.IsNullOrEmpty(Url)) { output.Attributes.Add("src", Url); } base.Process(context, output); }
public DataGripPage(object[][] source, DescriptionToken[] tokens, BaseVM owner) { InitializeComponent(); SetSource(source, tokens); Owner = owner; DataContext = this; }
public async void Submit(object param) { if (HomeVM.ClientName.Length <= 3) { HomeVM.StatusLabel.LabelMessage = "Your name must be at least 4 characters long!"; HomeVM.StatusLabel.ForegroundColor = System.Windows.Media.Brushes.Red; return; } var invalidCharacters = "/-?~`'\\\"|!@#$%^&*() "; if (invalidCharacters.Any(character => HomeVM.ClientName.Contains(character))) { HomeVM.StatusLabel.LabelMessage = "Your name contains an invalid character!"; HomeVM.StatusLabel.ForegroundColor = System.Windows.Media.Brushes.Red; return; } HomeVM.StatusLabel.LabelMessage = "Joining ..."; HomeVM.StatusLabel.ForegroundColor = System.Windows.Media.Brushes.OliveDrab; await Task.Delay(500); var response = CallGrpcService("connect"); if (response.Result.Status != ClientResponse.Types.Status.Success) { HomeVM.StatusLabel.LabelMessage = "Something went wrong while trying to connect to the server :("; HomeVM.StatusLabel.ForegroundColor = System.Windows.Media.Brushes.Red; return; } CurrentContext = new ChatVM(); _navigationStore.CurrentVM = CurrentContext; }
public TeacherVM Post([FromBody] UserCM value) { UserService service = new UserService(); User newUser = service.InsertUser(value.ToEntity()); return(BaseVM <object> .ToModel <TeacherVM>(newUser)); }
public override ValidationResult Validate(object value, CultureInfo cultureInfo) { BindingGroup group = (BindingGroup)value; StringBuilder error = null; foreach (var item in group.Items) { // aggregate errors IDataErrorInfo info = item as IDataErrorInfo; if (info != null) { if (!string.IsNullOrEmpty(info.Error)) { if (error == null) { error = new StringBuilder(); } error.Append((error.Length != 0 ? ", " : "") + info.Error); } } } BaseVM baseVM = GetBaseVM(group); if (error != null) { baseVM.SetStatusMessage(error.ToString(), true); return(new ValidationResult(false, error.ToString())); } baseVM.SetStatusMessage("", false); return(ValidationResult.ValidResult); }
/// <summary> /// Отображает модальное диалоговое окно с указанным представлением. /// </summary> /// <param name="viewModel">Указывает на представление, которое необходимо отобразить в модальном окне.</param> public bool ShowModalWindow(BaseVM viewModel, string caption = "", ModalWindowButtons buttonType = ModalWindowButtons.OnlyOkButton, string btnOkText = "Ок", string btnCancelText = "Отмена", Action <BaseVM> okResult = null, Action <BaseVM> cancelResult = null) { var result = false; if (viewModelToViewMap.TryGetValue(viewModel.GetType(), out Type viewType)) { var view = Activator.CreateInstance(viewType) as BaseView; view.ViewModel = viewModel; var modalWindow = new ModalWindow(view) { Owner = mainWindow }; modalWindow.DataContext = new ModalWindowVM(this, caption, buttonType, btnOkText, btnCancelText); result = modalWindow.ShowDialog() ?? false; if (result) { okResult?.Invoke(viewModel); } else { cancelResult?.Invoke(viewModel); } } return(result); }
public StoreEditPage(BaseVM vm) { this.BindingContext = vm; vm.Swipe = PanOperation.All; PanDecorator.ResetLastSelected(); InitializeComponent(); }
public ModelSyncher(BaseVM parent, ObservableCollection <ViewModelType> viewModelCollection, List <ModelType> modelCollection) { this.parent = parent; this.viewModelCollection = viewModelCollection; this.modelCollection = modelCollection; this.IsStopSync = false; viewModelCollection.CollectionChanged += new NotifyCollectionChangedEventHandler(model_CollectionChanged); }
public IActionResult About() { ViewData["Message"] = "Your application description page."; BaseVM mdl = new BaseVM(); mdl = UserToMdl(mdl); return(View(mdl)); }
public IActionResult Contact() { ViewData["Message"] = "Your contact page."; BaseVM mdl = new BaseVM(); mdl = UserToMdl(mdl); return(View(mdl)); }
/// <summary> /// 根据部门ID获取子部门ID列表 /// </summary> /// <param name="self"></param> /// <param name="id"></param> /// <returns></returns> public static List <long> GetChildrenDeparement(this BaseVM self, long id) { List <long> depids = self.DC.RunSP <long>("system_get_getchildrendeparement @pid", new SqlParameter { ParameterName = "pid ", Value = id }).ToList(); return(depids); }
public BaseVMTest() { _vm = new BaseVM(); Mock <IServiceProvider> mockService = new Mock <IServiceProvider>(); mockService.Setup(x => x.GetService(typeof(GlobalData))).Returns(new GlobalData()); mockService.Setup(x => x.GetService(typeof(Configs))).Returns(new Configs()); GlobalServices.SetServiceProvider(mockService.Object); }
public ActionResult BaseViewWithTitle(string title, params PagePart[] pageParts) { var model = new BaseVM { Parts = pageParts.Where(x => x != null).ToList(), Title = title, IsBootStrap = IsBootStrap }; return(ViewWithBaseVM(model)); }
public CondVM DeepCopy(BaseVM parent) { CondVM newCond = new CondVM(); newCond.Parent = parent; newCond.SelectedQuestionConstruct = SelectedQuestionConstruct; newCond.selectedOperatorCode = SelectedOperatorCode; newCond.CondValue = CondValue; return(newCond); }
public ActionResult CityInfoBlock(int id) { var block = CityInfoService.GetValues(id, x => x.Description); var model = new BaseVM { Title = "Блок города справа", RightSide = _.List(new PagePart(Htmls2.Cham(block))) }; return(ViewWithBaseVM(model)); }
public void UpdateView(object param) { if (param.ToString() == "StartMenu") { SelectedViewModel = new StartMenuViewModel(); } else if (param.ToString() == "Application") { SelectedViewModel = new ApplicationViewModel(); } }
public System.Windows.Input.ICommand AcceptChangeCmd() { return(new Command((it) => { BaseVM vm = it as BaseVM; if (vm != null) { vm.Parent.Navi.PopModalAsync(); } })); }
public override void OnSubVMCreated(BaseVM subVM) { if (subVM is FilterableMovieTableVM) { InitMovieTableVM(subVM as FilterableMovieTableVM); } else if (subVM is MovieDetailsVM) { InitMovieDetailsVM(subVM as MovieDetailsVM); } }
/// <summary> /// 当前登陆人是超级管理员 /// </summary> /// <param name="baseVM">传入this</param> /// <param name="ID">传入当前登陆人ID</param> /// <returns></returns> public static bool IsSuperAdministrator(this BaseVM baseVM, Guid ID) { try { var FrameworkRoleList = GetFrameworkRoleObject(baseVM.DC, ID); return(FrameworkRoleList != null && FrameworkRoleList.Where(x => x.RoleName == "超级管理员") !.Count() > 0); } catch (Exception) { return(false); } }
/// <summary> /// 当前登陆人角色不在其中 /// </summary> /// <param name="baseVM">传入this</param> /// <param name="ID">当前登陆人ID</param> /// <returns></returns> public static bool NoContainRoles(this BaseVM baseVM, Guid ID) { try { var FrameworkRoleList = GetFrameworkRoleObject(baseVM.DC, ID); return(FrameworkRoleList != null && FrameworkRoleList.Where(x => ContainRoles.IndexOf(x.RoleName) >= 0) !.Count() <= 0); } catch (Exception) { return(false); } }
public CondGroupVM DeepCopy(BaseVM parent) { CondGroupVM newCondGroup = new CondGroupVM(); newCondGroup.Parent = parent; foreach (CondVM cond in Conds) { CondVM newCond = cond.DeepCopy(newCondGroup); newCondGroup.Conds.Add(newCond); } return(newCondGroup); }
public IEnumerable <TeacherVM> GetAllUsers() { IEnumerable <User> list = service.GetAll(); return(list.Select(i => { var vm = BaseVM <object> .ToModel <TeacherVM>(i); vm.HomeroomClass = classService.GetHomeroomClass(i.Username) .Select(c => BaseVM <object> .ToModel <ClassVM>(c)); vm.TeachingClassQuantity = classService.GetTeacherCurrentClassQuantity(i.Username); return vm; })); }
public UserVM Login(string username, string password) { User user = repository.GetByUsernameAndPassword(username, password); if (user != null) { return(BaseVM <object> .ToModel <UserVM>(user)); } else { return(null); } }
public override void OnSubVMCreated(BaseVM childViewModel) { switch (childViewModel) { case ButtonTest buttonTestViewModel: InitButtonTest(buttonTestViewModel); break; case ButtonTestCounter buttonCounterViewModel: InitButtonTestCounter(buttonCounterViewModel); break; } }
/// <summary> /// 根据部门ID获取处1 /// </summary> /// <param name="self"></param> /// <param name="id"></param> /// <returns></returns> public static Subsection GetSubsection(this BaseVM self, long id) { Subsection Subsection = self.DC.RunSP <Subsection>("system_get_getsubsection @pid,@lcode", new SqlParameter { ParameterName = "pid ", Value = id }, new SqlParameter { ParameterName = "lcode ", Value = self.CurrentLanguage.LanguageCode } ).FirstOrDefault(); return(Subsection); }
public override void OnSubVMCreated(BaseVM vm) { if (vm is MasterList) { var masterList = vm as MasterList; masterList.ListItems = _webStoreService.GetAllBooks(); masterList.Selected += (sender, id) => SelectedItem?.Invoke(this, id); } else if (vm is Details) { var details = vm as Details; SelectedItem += (sender, id) => details.SetData(_webStoreService.GetBookById(id)); } }
Task OnNavigate(BaseVM vm, bool showModal) { var name = vm.GetType().Name.Replace("VM", "Page"); var pageType = Type.GetType($"{GetType().Namespace}.{name}"); var page = (BasePage)Activator.CreateInstance(pageType); page.BindingContext = vm; return(showModal ? Navigation.PushModalAsync(page) : Navigation.PushAsync(page)); }
public IEnumerable <ClassVM> GetAll() { var list = service.GetAll(); return(list.Select(i => { var vm = BaseVM <object> .ToModel <ClassVM>(i); vm.SubjectQuantity = i.ClassSubjects .Where(cs => cs.Status != (int)ClassSubjectEnums.STATUS_DISABLE).Count(); vm.StudentQuantity = i.ClassMembers .Where(cm => cm.Status != (int)ClassMemberEnums.STATUS_DISABLE).Count(); return vm; })); }
/// <summary> /// Updates a value of a view model. /// </summary> /// <param name="vmInstance">View model instance.</param> /// <param name="vmPath">View model property path.</param> /// <param name="newValue">New value.</param> protected virtual void UpdateVM(BaseVM vmInstance, string vmPath, string newValue) { try { object vmObject = vmInstance; var vmType = vmObject.GetType(); var path = vmPath.Split('.'); for (int i = 0; i < path.Length; i++) { var propName = path[i]; var propInfo = vmType.GetProperty(propName); if (propInfo == null) throw new UnresolvedVMUpdateException(); if (i < path.Length - 1) { // Path that starts with $ sign means it is a key to an IEnumerable property. // By convention we expect a method whose name is in this format: // <IEnumerable property name>_get (for example: ListContent_get) // to get the object whose key matches the given value in the path. if (path[i + 1].StartsWith("$")) { var key = path[i + 1].TrimStart('$'); var methodInfo = vmType.GetMethod(propName + "_get"); if (methodInfo == null) throw new UnresolvedVMUpdateException(); vmObject = methodInfo.Invoke(vmObject, new object[] { key }); if (vmObject == null) throw new UnresolvedVMUpdateException(); vmType = vmObject.GetType(); i++; } else { vmObject = propInfo.GetValue(vmObject); vmType = vmObject != null ? vmObject.GetType() : propInfo.PropertyType; } } else if (typeof(ICommand).IsAssignableFrom(propInfo.PropertyType) && vmObject != null) { // If the property type is ICommand, execute the command. (propInfo.GetValue(vmObject) as ICommand)?.Execute(newValue); } else if (propInfo.SetMethod != null && vmObject != null) { // Update the new value to the property. if (propInfo.PropertyType.IsClass && propInfo.PropertyType != typeof(string)) propInfo.SetValue(vmObject, JsonConvert.DeserializeObject(newValue, propInfo.PropertyType)); else { var typeConverter = TypeDescriptor.GetConverter(propInfo.PropertyType); if (typeConverter != null) propInfo.SetValue(vmObject, typeConverter.ConvertFromString(newValue)); } // Don't include the property we just updated in the ChangedProperties of the view model // unless the value is changed internally, so that we don't send the same value back to the client // during PushUpdates call by this VMController. var changedProperties = vmInstance.ChangedProperties; if (changedProperties.ContainsKey(vmPath) && (changedProperties[vmPath] ?? String.Empty).ToString() == newValue) { object value; changedProperties.TryRemove(vmPath, out value); } } } } catch (UnresolvedVMUpdateException) { // If we cannot resolve the property path, forward the info to the instance // to give it a chance to resolve it. vmInstance.OnUnresolvedUpdate(vmPath, newValue); } }
/// <summary> /// Returns whether current security context is authorized to access a view model. /// </summary> /// <param name="vmInstance">View model instance.</param> /// <returns>True if authorized.</returns> protected virtual bool IsAuthorized(BaseVM vmInstance) { var authAttr = vmInstance.GetType().GetCustomAttribute<AuthorizeAttribute>(); return authAttr == null || authAttr.IsAuthorized(Principal); }