public void XrmLookupServiceVerifyDoesNotCrashIfReferencedRecordDeleted() { //create object referencing a deleted record var solution = ReCreateTestSolution(); var testEntryObject = new TestXrmObjectEntryClass() { XrmLookupField = solution.ToLookup() }; XrmRecordService.Delete(solution); //verify the form loads and the invalid value is lceared var objectEntryViewModel = new ObjectEntryViewModel(null, null, testEntryObject, FakeFormController.CreateForObject(testEntryObject, new FakeApplicationController(), XrmRecordService)); objectEntryViewModel.LoadFormSections(); Assert.IsNull(testEntryObject.XrmLookupField); //lets just verify the cascade worked if we had not deleted it solution = ReCreateTestSolution(); testEntryObject = new TestXrmObjectEntryClass() { XrmLookupField = solution.ToLookup() }; objectEntryViewModel = new ObjectEntryViewModel(null, null, testEntryObject, FakeFormController.CreateForObject(testEntryObject, new FakeApplicationController(), XrmRecordService)); objectEntryViewModel.LoadFormSections(); Assert.IsNotNull(testEntryObject.XrmLookupField); Assert.IsNotNull(testEntryObject.XrmLookupFieldCascaded); }
private static void LoadForm(ObjectEntryViewModel entryForm) { entryForm.LoadFormSections(); foreach (var grid in entryForm.SubGrids) Assert.IsNotNull(grid.DynamicGridViewModel.GridRecords); }
public void RecordEntryViewModelTestAllFieldTypes() { var applicationController = new FakeApplicationController(); var settingsObject = new SettingsTestAllFieldTypes { SavedInstances = new[] { new TestAllFieldTypes() { StringField = "Foo" } } }; applicationController.RegisterInstance(typeof(SettingsTestAllFieldTypes), settingsObject); //create the form var testObject = new TestAllFieldTypes(); var lookupService = FakeRecordService.Get(); var formController = FormController.CreateForObject(testObject, applicationController, lookupService); var entryViewModel = new ObjectEntryViewModel(() => { }, () => { }, testObject, formController); //populate all the fields entryViewModel.LoadFormSections(); PopulateRecordEntry(entryViewModel, populateSubgrids: true); //save the record Assert.IsTrue(entryViewModel.Validate()); entryViewModel.SaveButtonViewModel.Invoke(); }
protected override void CompleteDialogExtention() { var aggregatedSettings = ApplicationController.ResolveType <SettingsAggregator>(); var viewModels = new List <RecordEntryFormViewModel>(); foreach (var type in aggregatedSettings.SettingTypes) { var mapper = new ClassSelfMapper(); var instance = mapper.Map(ApplicationController.ResolveType(type)); var viewModel = new ObjectEntryViewModel(null, null, instance, FormController.CreateForObject(instance, ApplicationController, null)); viewModel.DisplayRightEdgeButtons = false; viewModel.OnSave = () => { ApplicationController.ResolveType <ISettingsManager>().SaveSettingsObject(instance); ApplicationController.RegisterInstance(instance); viewModel.ValidationPrompt = "The Settings Have Been Saved"; }; viewModels.Add(viewModel); } var mainViewModel = new RecordEntryAggregatorViewModel(viewModels, ApplicationController); Controller.LoadToUi(mainViewModel); }
private static void LoadSavedObject(object selectedObject, ObjectEntryViewModel loadIntoForm) { var formObject = loadIntoForm.GetObject(); loadIntoForm.ApplicationController.LogEvent("Load Request Loaded", new Dictionary <string, string> { { "Type", formObject.GetType().Name } }); var mapper = new ClassSelfMapper(); mapper.Map(selectedObject, formObject); if (formObject is ServiceRequestBase) { ((ServiceRequestBase)formObject).DisplaySavedSettingFields = false; } loadIntoForm.LoadingViewModel.IsLoading = true; loadIntoForm.LoadingViewModel.LoadingMessage = "Please Wait While Loading"; //allow loading to display Thread.Sleep(1000); //reload the parent parent form fo4r the updated object loadIntoForm.Reload(); foreach (var grid in loadIntoForm.SubGrids) { grid.DynamicGridViewModel.ReloadGrid(); } loadIntoForm.ApplicationController.LogEvent("Load Request Completed", new Dictionary <string, string> { { "Type", formObject.GetType().Name }, { "Is Completed Event", true.ToString() } }); }
protected override void CompleteDialogExtention() { //okay all this does is load a form for navigating autonumbers var autonumberNavigator = new AutonumberNavigator(); var formController = FormController.CreateForObject(autonumberNavigator, ApplicationController, XrmRecordService); var viewModel = new ObjectEntryViewModel(null, null, autonumberNavigator, formController); Controller.LoadToUi(viewModel); }
protected override void LoadDialogExtention() { var recordService = new ObjectRecordService(ObjectToEnter, LookupService, OptionsetLimitedValues, ApplicationController, ObjectTypeMaps); var formService = new ObjectFormService(ObjectToEnter, recordService, ObjectTypeMaps); ViewModel = new ObjectEntryViewModel(StartNextAction, OnCancel, ObjectToEnter, new FormController(recordService, formService, ApplicationController), OnlyValidate); Controller.LoadToUi(ViewModel); }
private void DownloadTemplates(RecordEntryFormViewModel viewModel) { //okay so something to generate one or more csv files with column headings //think will just create a child form entry, generate on save then return to the dialog form try { if (viewModel is ObjectEntryViewModel) { var oevm = viewModel as ObjectEntryViewModel; var templatesRequest = new GenerateTemplatesRequest(); //this is the save function after entering the csvs to generate Action createTemplatesAndReturn = () => { var serviceConnection = viewModel.RecordService.LookupService; //loop through each csv entered and create foreach (var config in templatesRequest.CsvsToGenerate) { var recordType = config.RecordType.Key; var fieldsInEntity = serviceConnection.GetFields(recordType).ToArray(); var fieldsToInclude = config.AllFields ? fieldsInEntity .Where(f => { var mt = serviceConnection.GetFieldMetadata(f, recordType); return(mt.Createable || mt.Writeable); }).ToArray() : config.FieldsToInclude.Select(f => f.RecordField.Key).Intersect(fieldsInEntity).ToArray(); var columnHeadings = templatesRequest.UseSchemaNames ? fieldsToInclude : fieldsToInclude.Select(f => serviceConnection.GetFieldLabel(f, recordType)).ToArray(); var csvText = string.Join(",", columnHeadings.OrderBy(s => s)); var fileNameNoExt = templatesRequest.UseSchemaNames ? recordType : serviceConnection.GetCollectionName(recordType); FileUtility.WriteToFile(templatesRequest.FolderToSaveInto.FolderPath, fileNameNoExt + ".csv", csvText); } viewModel.ApplicationController.StartProcess("explorer", templatesRequest.FolderToSaveInto.FolderPath); //reload the form and notify viewModel.ClearChildForms(); viewModel.LoadCustomFunctions(); }; //load the entry form var os = new ObjectRecordService(templatesRequest, viewModel.RecordService.LookupService, null, viewModel.ApplicationController, null); var ofs = new ObjectFormService(templatesRequest, os, null); var fc = new FormController(os, ofs, viewModel.ApplicationController); var vm = new ObjectEntryViewModel(createTemplatesAndReturn, () => viewModel.ClearChildForms(), templatesRequest, fc); viewModel.LoadChildForm(vm); } } catch (Exception ex) { ApplicationController.ThrowException(ex); } }
public CompletionScreenViewModel(Action onClose, object completionObject, IApplicationController controller) : base(controller) { if (completionObject != null) { var formController = FormController.CreateForObject(completionObject, ApplicationController, null); CompletionDetails = new ObjectEntryViewModel(null, onClose, completionObject, formController, cancelButtonLabel: "Close"); CompletionDetails.IsReadOnly = true; } }
public ObjectEntryViewModel LoadToObjectEntryViewModel(object objectToEnter) { var applicationController = new FakeApplicationController(); var recordService = new ObjectRecordService(objectToEnter, applicationController); var formService = new ObjectFormService(objectToEnter, recordService); var viewModel = new ObjectEntryViewModel(EmptyMethod, EmptyMethod, objectToEnter, new FormController(recordService, formService, applicationController)); viewModel.LoadFormSections(); Assert.IsNotNull(viewModel.FormSectionsAsync); return(viewModel); }
private static void PopulateRowForMessage(ObjectEntryViewModel triggerEntry, string message) { foreach (var field in triggerEntry.FieldViewModels) { if (field.ValueObject == null) { if (field is LookupFieldViewModel) { var typeFieldViewModel = (LookupFieldViewModel)field; if (field.FieldName == "Message") { typeFieldViewModel.Value = typeFieldViewModel.LookupService.ToLookup(typeFieldViewModel.ItemsSource.First(m => m.Name == message).Record); } else if (typeFieldViewModel.UsePicklist) { typeFieldViewModel.Value = typeFieldViewModel.LookupService.ToLookup(typeFieldViewModel.ItemsSource.First(p => p.Record != null).Record); } ; } if (field is PicklistFieldViewModel) { var typeFieldViewModel = (PicklistFieldViewModel)field; typeFieldViewModel.Value = typeFieldViewModel.ItemsSource.First(); } if (field is RecordTypeFieldViewModel) { var typeFieldViewModel = (RecordTypeFieldViewModel)field; typeFieldViewModel.Value = typeFieldViewModel.ItemsSource.First(); } if (field.FieldName == nameof(PluginTrigger.FilteringFields) && message == "Update") { var multiSelectField = triggerEntry.GetFieldViewModel <RecordFieldMultiSelectFieldViewModel>(nameof(PluginTrigger.FilteringFields)); SelectItems(multiSelectField, 1, 2); } if (field.FieldName == nameof(PluginTrigger.PreImageAllFields) && message == "Update") { triggerEntry.GetFieldViewModel <BooleanFieldViewModel>(nameof(PluginTrigger.PreImageAllFields)).Value = false; } if (field.FieldName == nameof(PluginTrigger.PreImageFields) && message == "Update") { var multiSelectField = triggerEntry.GetFieldViewModel <RecordFieldMultiSelectFieldViewModel>(nameof(PluginTrigger.PreImageFields)); SelectItems(multiSelectField, 1, 2); } } } triggerEntry.GetPicklistFieldFieldViewModel(nameof(PluginTrigger.Mode)).ValueObject = PluginTrigger.PluginMode.Asynch; triggerEntry.GetPicklistFieldFieldViewModel(nameof(PluginTrigger.Stage)).ValueObject = PluginTrigger.PluginStage.PostEvent; triggerEntry.GetBooleanFieldFieldViewModel(nameof(PluginTrigger.PreImageAllFields)).Value = true; triggerEntry.GetLookupFieldFieldViewModel(nameof(PluginTrigger.SpecificUserContext)).Value = null; var filteringAttributesField = triggerEntry.GetFieldViewModel <RecordFieldMultiSelectFieldViewModel>(nameof(PluginTrigger.FilteringFields)); DeselectAll(filteringAttributesField); }
protected override void LoadDialogExtention() { LoadingViewModel.LoadingMessage = "Loading Entry Form"; var recordService = new ObjectRecordService(ObjectToEnter, LookupService, OptionsetLimitedValues, ApplicationController, ObjectTypeMaps); var formService = new ObjectFormService(ObjectToEnter, recordService, ObjectTypeMaps); ViewModel = new ObjectEntryViewModel(StartNextAction, OnCancel, ObjectToEnter, new FormController(recordService, formService, ApplicationController), OnlyValidate, saveButtonLabel: SaveButtonLabel, cancelButtonLabel: CancelButtonLabel); if (InitialMessage != null) { ViewModel.ValidationPrompt = InitialMessage; } Controller.LoadToUi(ViewModel); }
private void SetNewAction() { if (SettingsAttribute.AllowAddNew) { NewAction = () => { var settingsObject = GetSettingsObject(); var propertyInfo = settingsObject.GetType().GetProperty(SettingsAttribute.PropertyName); var enumerateType = propertyInfo.PropertyType.GenericTypeArguments[0]; var newSettingObject = enumerateType.CreateFromParameterlessConstructor(); var objectRecordService = new ObjectRecordService(newSettingObject, ApplicationController, null); var formService = new ObjectFormService(newSettingObject, objectRecordService); var formController = new FormController(objectRecordService, formService, ApplicationController); Action onSave = () => { //add the new item to the permanent settings var settingsManager = ApplicationController.ResolveType <ISettingsManager>(); settingsObject = GetSettingsObject(); var settingsService = new ObjectRecordService(settingsObject, ApplicationController); var currentSettings = settingsService.RetrieveAll(enumerateType.AssemblyQualifiedName, null) .Select(r => ((ObjectRecord)r).Instance) .ToList(); currentSettings.Add(newSettingObject); settingsObject.SetPropertyValue(SettingsAttribute.PropertyName, enumerateType.ToNewTypedEnumerable(currentSettings)); settingsManager.SaveSettingsObject(settingsObject); ValueObject = newSettingObject; if (UsePicklist) { //reload the picklist ValueObject = newSettingObject; LoadPicklistItems(); } else { SetEnteredTestWithoutClearingValue(ValueObject.ToString()); } RecordEntryViewModel.ClearChildForm(); }; var newSettingForm = new ObjectEntryViewModel(onSave, RecordEntryViewModel.ClearChildForm, newSettingObject, formController); RecordEntryViewModel.LoadChildForm(newSettingForm); }; } }
public TResponse NavigateAndProcessDialog <TDialogModule, TDialog, TResponse>(object instanceEntered) where TDialogModule : DialogModule <TDialog>, new() where TDialog : DialogViewModel where TResponse : class { var dialog = NavigateToDialog <TDialogModule, TDialog>(); var entryForm = GetSubObjectEntryViewModel(dialog); var saveRequest = false; Type savedRequestType = null; if (entryForm is ObjectEntryViewModel) { entryForm.LoadFormSections(); var oevm = (ObjectEntryViewModel)entryForm; foreach (var grid in oevm.SubGrids) { if (grid.DynamicGridViewModel.LoadedCallback != null) { grid.DynamicGridViewModel.LoadedCallback(); } } } EnterAndSaveObject(instanceEntered, entryForm); if (saveRequest) { //okay lets delete the request we saved earlier (and any others) ObjectEntryViewModel oevm = LoadSavedRequestsEntryForm(savedRequestType); foreach (var grid in oevm.SubGrids) { while (grid.GridRecords.Any()) { grid.GridRecords.First().DeleteRow(); } } oevm.SaveButtonViewModel.Invoke(); } return(dialog.CompletionItem as TResponse); }
public CompletionScreenViewModel(Action onClose, string heading, IEnumerable <XrmButtonViewModel> options, object completionObject, IApplicationController controller) : base(controller) { Heading = new HeadingViewModel(heading, controller); CompletionHeadingText = heading; CompletionOptions = options; if (completionObject != null) { var formController = FormController.CreateForObject(completionObject, ApplicationController, null); CompletionDetails = new ObjectEntryViewModel(null, null, completionObject, formController); CompletionDetails.IsReadOnly = true; CompletionDetails.PropertyChanged += CompletionDetails_PropertyChanged; } //CompletionDetails = new ObjectsGridSectionViewModel("Summary", completionDetails, controller); CloseButton = new XrmButtonViewModel("Close", onClose, controller); }
public override RecordEntryFormViewModel GetEditRowViewModel(string subGridName, RecordEntryViewModelBase parentForm, Action <IRecord> onSave, Action onCancel, GridRowViewModel gridRow) { var record = gridRow.GetRecord(); if (!(record is ObjectRecord)) { throw new NotSupportedException(string.Format("Error Expected Object Of Type {0}", typeof(ObjectRecord).Name)); } var newRecord = (ObjectRecord)record; //need to load the existing row to this //lets start a dialog to add it on complete var mapper = new ClassSelfMapper(); var newObject = mapper.Map(newRecord.Instance); var recordService = new ObjectRecordService(newObject, ObjectRecordService.LookupService, ObjectRecordService.OptionSetLimitedValues, ObjectRecordService, subGridName, parentForm.ApplicationController); var viewModel = new ObjectEntryViewModel( () => onSave(new ObjectRecord(newObject)), onCancel, newObject, new FormController(recordService, new ObjectFormService(newObject, recordService), parentForm.FormController.ApplicationController), parentForm, subGridName, parentForm.OnlyValidate); return(viewModel); }
public void XrmLookupServiceVerifyDoesNotCrashIfConnectionDoesNotWork() { try { var solution = ReCreateTestSolution(); var testEntryObject = new TestXrmObjectEntryClass() { XrmLookupField = solution.ToLookup() }; var classSelfMapper = new ClassSelfMapper(); var newConnection = classSelfMapper.Map(GetXrmRecordConfiguration()); newConnection.OrganizationUniqueName = "Foo"; var newService = new XrmRecordService(newConnection); var objectEntryViewModel = new ObjectEntryViewModel(null, null, testEntryObject, FakeFormController.CreateForObject(testEntryObject, new FakeApplicationController(), newService)); objectEntryViewModel.LoadFormSections(); Assert.IsNotNull(testEntryObject.XrmLookupField); Assert.IsNotNull(testEntryObject.XrmLookupFieldCascaded); } catch (FakeUserMessageException) { } }
private static void LoadSavedObject(object selectedObject, ObjectEntryViewModel loadIntoForm) { var formObject = loadIntoForm.GetObject(); var mapper = new ClassSelfMapper(); mapper.Map(selectedObject, formObject); if (formObject is ServiceRequestBase) { ((ServiceRequestBase)formObject).DisplaySavedSettingFields = false; } loadIntoForm.LoadingViewModel.IsLoading = true; //allow loading to display Thread.Sleep(1000); //reload the parent parent form fo4r the updated object loadIntoForm.Reload(); foreach (var grid in loadIntoForm.SubGrids) { grid.DynamicGridViewModel.ReloadGrid(); } }
internal override RecordEntryFormViewModel GetLoadRowViewModel(string subGridName, RecordEntryViewModelBase parentForm, Action <IRecord> onSave, Action onCancel) { var propertyInfo = ObjectToEnter.GetType().GetProperty(subGridName); if (propertyInfo.GetCustomAttribute <FormEntry>() != null) { //lets start a dialog to add it on complete var fieldMetadata = (EnumerableFieldMetadata)ObjectRecordService.GetFieldMetadata(propertyInfo.Name, ObjectToEnter.GetType().AssemblyQualifiedName); var newRecord = (ObjectRecord)ObjectRecordService.NewRecord(fieldMetadata.EnumeratedTypeQualifiedName); var newObject = newRecord.Instance; var recordService = new ObjectRecordService(newObject, ObjectRecordService.LookupService, ObjectRecordService.OptionSetLimitedValues, ObjectRecordService, subGridName, parentForm.ApplicationController); var viewModel = new ObjectEntryViewModel( () => onSave(new ObjectRecord(newObject)), onCancel, newObject, new FormController(recordService, new ObjectFormService(newObject, recordService), parentForm.FormController.ApplicationController), parentForm, subGridName, parentForm.OnlyValidate); return(viewModel); //ideally could hide the parent dialog temporarily and load this one } //if the object specifies use a form then use the form/dialog else { return(null); } }
/// <summary> /// Load a form for saving the details /// </summary> public void SaveObject(RecordEntryFormViewModel viewModel) { try { //subgrids don't map directly to object so need to unload them to object //before saving the record if (viewModel is ObjectEntryViewModel) { var oevm = viewModel as ObjectEntryViewModel; oevm.LoadSubgridsToObject(); var theObject = oevm.GetObject(); var theObjectType = theObject.GetType(); if (!theObjectType.IsTypeOf(typeof(IAllowSaveAndLoad))) { throw new Exception(string.Format("type {0} is not of type {1}", theObjectType.Name, typeof(IAllowSaveAndLoad).Name)); } ApplicationController.LogEvent("Save Request Loaded", new Dictionary <string, string> { { "Type", theObjectType.Name } }); //this is an object specifically for entering the name and autoload properties //they are mapped into the IAllowSaveAndLoad object after entry then it is saved var saveObject = new SaveAndLoadFields(); Action saveSettings = () => { //map the entered properties into the new object we are saving var mapper = new ClassSelfMapper(); mapper.Map(saveObject, theObject); var settingsManager = viewModel.ApplicationController.ResolveType(typeof(ISettingsManager)) as ISettingsManager; var settings = settingsManager.Resolve <SavedSettings>(theObjectType); //if we selected autoload then set it false for the others if (saveObject.Autoload) { foreach (var item in settings.SavedRequests.Cast <IAllowSaveAndLoad>()) { item.Autoload = false; } } //add the one and save settings.SavedRequests = settings.SavedRequests.Union(new[] { theObject }).ToArray(); settingsManager.SaveSettingsObject(settings, theObjectType); ApplicationController.LogEvent("Save Request Completed", new Dictionary <string, string> { { "Type", theObjectType.Name }, { "Is Completed Event", true.ToString() }, { "Autoload", saveObject.Autoload.ToString() } }); //reload the form and notify viewModel.ClearChildForms(); viewModel.LoadCustomFunctions(); viewModel.ApplicationController.UserMessage($"You Input Has Been Saved. To Load A Saved Input Or Generate A Bat Executable Click The '{LoadButtonLabel}' Button"); }; //load the entry form var os = new ObjectRecordService(saveObject, viewModel.ApplicationController, null); var ofs = new ObjectFormService(saveObject, os, null); var fc = new FormController(os, ofs, viewModel.ApplicationController); var vm = new ObjectEntryViewModel(saveSettings, () => viewModel.ClearChildForms(), saveObject, fc); viewModel.LoadChildForm(vm); } } catch (Exception ex) { ApplicationController.ThrowException(ex); } }
/// <summary> /// Load a form displaying the saved requests for selection /// </summary> public void LoadObject(RecordEntryFormViewModel re) { try { if (re is ObjectEntryViewModel) { var oevm = re as ObjectEntryViewModel; var theObject = oevm.GetObject(); var theObjectType = theObject.GetType(); ApplicationController.LogEvent("Edit Saved Requests Loaded", new Dictionary <string, string> { { "Type", theObjectType.Name } }); var settingsManager = ApplicationController.ResolveType(typeof(ISettingsManager)) as ISettingsManager; if (settingsManager == null) { throw new NullReferenceException("settingsManager"); } //get the saved requests var savedSettings = settingsManager.Resolve <SavedSettings>(theObjectType); if (!savedSettings.SavedRequests.Any()) { ApplicationController.UserMessage(string.Format("There are no saved {0} records", theObjectType.GetDisplayName())); return; } //set the dsaved requests to display the saved request details foreach (var savedSetting in savedSettings.SavedRequests) { var casted = savedSetting as IAllowSaveAndLoad; if (casted != null) { casted.DisplaySavedSettingFields = true; } } //this tells the form to use this type for the properties list of objects var objectTypeMaps = new Dictionary <string, Type>() { { nameof(SavedSettings.SavedRequests), theObjectType } }; //this tells the form to only validate the name property of saved requests var onlyValidate = new Dictionary <string, IEnumerable <string> >() { { theObjectType.AssemblyQualifiedName, new [] { nameof(IAllowSaveAndLoad.Name) } } }; //on save any changes should be saved in the settings Action savedLoadForm = () => { settingsManager.SaveSettingsObject(savedSettings, theObjectType); oevm.LoadCustomFunctions(); oevm.ClearChildForms(); }; //load the form var dialogController = new DialogController(ApplicationController); var recordService = new ObjectRecordService(savedSettings, null, null, ApplicationController, objectTypeMaps); var formService = new ObjectFormService(savedSettings, recordService, objectTypeMaps); formService.AllowLookupFunctions = false; var vm = new ObjectEntryViewModel(savedLoadForm, oevm.ClearChildForms, savedSettings, new FormController(recordService, formService, ApplicationController), re, "LOADING", onlyValidate: onlyValidate); oevm.LoadChildForm(vm); ApplicationController.LogEvent("Edit Saved Requests Completed", new Dictionary <string, string> { { "Type", theObjectType.Name }, { "Is Completed Event", true.ToString() } }); } } catch (Exception ex) { ApplicationController.ThrowException(ex); } }