Exemplo n.º 1
0
        protected override void LoadDialogExtention()
        {
            var savedRequests = ApplicationController
                                .ResolveType <ISettingsManager>()
                                .Resolve <SavedSettings>(typeof(TRequest));

            if (savedRequests != null && savedRequests.SavedRequests != null)
            {
                var autoLoads = savedRequests.SavedRequests
                                .Where(r => r is TRequest)
                                .Cast <TRequest>()
                                .Where(r => r.Autoload)
                                .ToArray();
                if (autoLoads.Any())
                {
                    var mapper = new ClassSelfMapper();
                    mapper.Map(autoLoads.First(), Request);
                }
            }
            if (SkipObjectEntry)
            {
                var subDialogs = new List <DialogViewModel>(SubDialogs);
                subDialogs.Remove(ConfigEntryDialog);
                SubDialogs = subDialogs;
            }
            StartNextAction();
        }
Exemplo n.º 2
0
 private void CopyFieldsTo(IRecord copyFrom, IRecord copyTo, IEnumerable <string> fields)
 {
     if (fields == null)
     {
         fields = copyFrom.GetFieldsInEntity();
     }
     foreach (var field in fields)
     {
         var value = copyFrom.GetField(field);
         if (value == null ||
             value is string ||
             value is int ||
             value is decimal ||
             value is DateTime ||
             value is bool)
         {
             copyTo.SetField(field, value, this);
         }
         else if (value is IRecord[])
         {
             var newValue = ((IRecord[])value).Select(r => Clone(r, null)).ToArray();
             copyTo.SetField(field, newValue, this);
         }
         else
         {
             var mapper = new ClassSelfMapper();
             copyTo.SetField(field, mapper.Map(copyFrom.GetField(field)), this);
         }
     }
 }
Exemplo n.º 3
0
        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() }
            });
        }
Exemplo n.º 4
0
        public void NavigateTo(object navigationObject, UriQuery uriQuery, bool showCompletionScreen = true, bool isModal = false)
        {
            uriQuery = uriQuery ?? new UriQuery();

            if (navigationObject is DialogViewModel)
            {
                var dialog = navigationObject as DialogViewModel;
                foreach (var arg in uriQuery.Arguments)
                {
                    var dialogProperty = dialog.GetType().GetProperty(arg.Key);
                    if (dialogProperty != null)
                    {
                        if (dialogProperty.PropertyType == typeof(bool))
                        {
                            dialog.SetPropertyValue(dialogProperty.Name, bool.Parse(arg.Value));
                        }
                        else
                        {
                            var argObject     = JsonHelper.JsonStringToObject(arg.Value, dialogProperty.PropertyType);
                            var propertyValue = dialog.GetPropertyValue(dialogProperty.Name) ?? argObject;
                            var mapper        = new ClassSelfMapper();
                            mapper.Map(argObject, propertyValue);
                        }
                    }
                }

                LoadDialog(dialog, showCompletionScreen: showCompletionScreen, isModal: isModal);
            }
            else
            {
                throw new NotImplementedException("Not implemented for type " + navigationObject?.GetType().Name);
            }
        }
        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);
        }
Exemplo n.º 6
0
        public static SavedXrmRecordConfiguration CreateNew(IXrmRecordConfiguration xrmRecordConfiguration)
        {
            var mapper          = new ClassSelfMapper();
            var savedConnection = new SavedXrmRecordConfiguration();

            mapper.Map(xrmRecordConfiguration, savedConnection);
            return(savedConnection);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Load the selected grid row's object into the parent parent form
        /// </summary>
        public void LoadSelected(DynamicGridViewModel g)
        {
            try
            {
                if (!(g.SelectedRows.Count() == 1))
                {
                    g.ApplicationController.UserMessage("You Must Select 1 Row To Load");
                    return;
                }
                var parentForm = g.ParentForm as ObjectEntryViewModel;
                if (parentForm == null)
                {
                    throw new NullReferenceException(string.Format("Error parent form is not of type {0}", typeof(ObjectEntryViewModel)));
                }

                //get the selected object
                var selectionSubGrid     = parentForm.GetEnumerableFieldViewModel(nameof(SavedSettings.SavedRequests));
                var selectedObjectRecord = selectionSubGrid.DynamicGridViewModel.SelectedRows.Count() == 1
                    ? selectionSubGrid.DynamicGridViewModel.SelectedRows.First().GetRecord() as ObjectRecord : null;
                var selectedObject = selectedObjectRecord == null ? null : selectedObjectRecord.Instance;

                if (selectedObject != null)
                {
                    //map the selected object into the parent parent forms object
                    var parentParentForm = parentForm.ParentForm as ObjectEntryViewModel;
                    if (parentParentForm == null)
                    {
                        throw new NullReferenceException(string.Format("Error parent parent form is not of type {0}", typeof(ObjectEntryViewModel)));
                    }

                    var parentFormObject = parentParentForm.GetObject();
                    var mapper           = new ClassSelfMapper();
                    mapper.Map(selectedObject, parentFormObject);
                    if (parentFormObject is ServiceRequestBase)
                    {
                        ((ServiceRequestBase)parentFormObject).DisplaySavedSettingFields = false;
                    }

                    parentParentForm.LoadingViewModel.IsLoading = true;
                    //allow loading to display
                    Thread.Sleep(1000);

                    //reload the parent parent form fo4r the updated object
                    parentParentForm.Reload();
                    foreach (var grid in parentParentForm.SubGrids)
                    {
                        grid.DynamicGridViewModel.ReloadGrid();
                    }
                }
                parentForm.LoadSubgridsToObject();
                parentForm.OnSave();
            }
            catch (Exception ex)
            {
                ApplicationController.ThrowException(ex);
            }
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
 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)
     {
     }
 }
Exemplo n.º 10
0
        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();
            }
        }
Exemplo n.º 11
0
        /// <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);
            }
        }