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);
        }
示例#3
0
        protected void AddObjectToUi(object objectToDisplay, Action nextAction = null, string nextActionLabel = null, Action cancelAction = null, Action backAction = null)
        {
            var vm = new ObjectDisplayViewModel(objectToDisplay, FormController.CreateForObject(objectToDisplay, ApplicationController, null)
                                                , nextAction: nextAction, nextActionLabel: nextActionLabel, cancelAction: cancelAction, backAction: backAction);

            Controller.LoadToUi(vm);
        }
 public void SetDetailObject(object detailObject)
 {
     ApplicationController.DoOnAsyncThread(() =>
     {
         DetailObjectViewModel = new ObjectDisplayViewModel(detailObject, FormController.CreateForObject(detailObject, ApplicationController, null));
         OnPropertyChanged(nameof(DetailObjectViewModel));
     });
 }
        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);
        }
 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 ConditionViewModel(QueryCondition conditionObject, string recordType, IRecordService recordService, IApplicationController controller)
            : base(FormController.CreateForObject(conditionObject, controller, recordService, optionSetLimitedvalues: new Dictionary<string, IEnumerable<string>> { { nameof(QueryCondition.FieldName), GetValidFields(recordType, recordService) } }))
        {
            _queryCondition = conditionObject;
            _queryConditionRecord = new ObjectRecord(conditionObject);

            var metadata = FormService.GetFormMetadata(GetRecord().Type, RecordService);
            var sections = metadata.FormSections;
            var firstSection = sections.First();
            var sectionViewModel = new FieldSectionViewModel(
                        (FormFieldSection)firstSection,
                        this
                        );
            FormFieldSection = sectionViewModel;
            OnLoad();
        }
示例#8
0
        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);
        }
        protected override void CompleteDialogExtention()
        {
            if (SaveSettings)
            {
                var isMovingFolder = VisualStudioService.GetSolutionFolder(VisualStudioService.ItemFolderName) == null &&
                                     VisualStudioService.GetItemText("solution.xrmconnection", "SolutionItems") != null;
                base.CompleteDialogExtention();
                //set the active connection to the connection selected as active
                if (SettingsObject.Connections != null)
                {
                    var activeConnections = SettingsObject.Connections.Where(c => c.Active);
                    if (activeConnections.Any())
                    {
                        var activeConnection = activeConnections.First();
                        var settingsManager  = ApplicationController.ResolveType(typeof(ISettingsManager)) as ISettingsManager;
                        if (settingsManager == null)
                        {
                            throw new NullReferenceException("settingsManager");
                        }
                        settingsManager.SaveSettingsObject(activeConnection);

                        XrmConnectionModule.RefreshXrmServices(activeConnection, ApplicationController, xrmRecordService: (RefreshActiveServiceConnection ? XrmRecordService : null));
                        LookupService = (XrmRecordService)ApplicationController.ResolveType(typeof(XrmRecordService));
                    }
                }
                if (isMovingFolder)
                {
                    var openIt = ApplicationController.UserConfirmation("This Visual Studio extention is changing the way saved settings are stored. Click yes to open a window outlining the changes, and detailing code changes required if you use instances of the Xrm Solution Template");
                    if (openIt)
                    {
                        var blah             = new SettingsFolderMoving();
                        var displaySomething = new ObjectDisplayViewModel(blah, FormController.CreateForObject(blah, ApplicationController, null));
                        ApplicationController.NavigateTo(displaySomething);
                    }
                }
            }
            CompletionMessage = "Settings Updated";
        }
        public StringAutocompleteViewModel(StringFieldViewModel stringField, AutocompleteFunction autocompleteFunction)
            : base(stringField.ApplicationController)
        {
            SearchText           = stringField.Value;
            StringField          = stringField;
            AutocompleteFunction = autocompleteFunction;
            var typeAheadOptions = new TypeAheadOptions();

            var typeAheadRecordService = new ObjectRecordService(typeAheadOptions, ApplicationController);
            var formController         = FormController.CreateForObject(typeAheadOptions, ApplicationController, null);

            IEnumerable <object> autoCompleteStrings = null;

            if (AutocompleteFunction.CacheAsStaticList)
            {
                try
                {
                    autoCompleteStrings = autocompleteFunction.GetAutocompleteStrings(StringField.RecordEntryViewModel);
                }
                catch (Exception ex)
                {
                    StringField.AddError($"Error Loading Autocomplete {ex.Message}\n{ex.DisplayString()}");
                }
            }

            Func <bool, GetGridRecordsResponse> getGridRecords = (ignorePages) =>
            {
                try
                {
                    LoadOptionsError    = null;
                    autoCompleteStrings = autoCompleteStrings != null && AutocompleteFunction.CacheAsStaticList
                            ? autoCompleteStrings
                            : autocompleteFunction
                                          .GetAutocompleteStrings(StringField.RecordEntryViewModel);
                    if (autoCompleteStrings == null)
                    {
                        return(new GetGridRecordsResponse(new IRecord[0]));
                    }
                    var searchToLower = SearchText?.ToLower();
                    typeAheadOptions.Options = autoCompleteStrings
                                               .Where(ta => searchToLower == null || AutocompleteFunction.SearchFields.Any(sf => ta.GetPropertyValue(sf)?.ToString().ToLower().StartsWith(searchToLower) ?? false))
                                               .OrderBy(ta => (string)ta.GetPropertyValue(AutocompleteFunction.SortField))
                                               .ThenBy(ta => (string)ta.GetPropertyValue(AutocompleteFunction.ValueField));

                    var records = typeAheadOptions
                                  .Options
                                  .Select(o => new ObjectRecord(o))
                                  .Take(MaxRecordsForLookup)
                                  .ToArray();
                    if (stringField.DisplayAutocomplete &&
                        (!records.Any() ||
                         (records.Count() == 1 && records.First().GetStringField(AutocompleteFunction.ValueField)?.ToLower() == searchToLower)))
                    {
                        stringField.DisplayAutocomplete = false;
                    }
                    else
                    {
                        stringField.DisplayAutocomplete = true;
                    }
                    return(new GetGridRecordsResponse(records));
                }
                catch (Exception ex)
                {
                    LoadOptionsError = $"Autocomplete could not be loaded\n\n{ex.Message}{(ex.InnerException == null ? null : ("\n\n" + ex.InnerException.Message))}\n\n{ex.StackTrace}";
                    return(new GetGridRecordsResponse(new IRecord[0]));
                }
            };

            DynamicGridViewModel = new DynamicGridViewModel(ApplicationController)
            {
                FormController = formController,
                GetGridRecords = getGridRecords,
                OnDoubleClick  = OnDoubleClick,
                ViewType       = ViewType.LookupView,
                RecordService  = typeAheadRecordService,
                RecordType     = AutocompleteFunction.RecordType,
                IsReadOnly     = true,
                DisplayHeaders = false,
                NoMargins      = true,
                FieldMetadata  = AutocompleteFunction.GridFields
            };
        }
示例#11
0
        protected override void LoadDialogExtention()
        {
            var objectDisplayViewModel = new ObjectDisplayViewModel(About, FormController.CreateForObject(About, ApplicationController, null));

            Controller.LoadToUi(objectDisplayViewModel);
        }