Exemplo n.º 1
0
        public static SavedXrmRecordConfiguration CreateNew(IXrmRecordConfiguration xrmRecordConfiguration)
        {
            var mapper          = new ClassSelfMapper();
            var savedConnection = new SavedXrmRecordConfiguration();

            mapper.Map(xrmRecordConfiguration, savedConnection);
            return(savedConnection);
        }
Exemplo n.º 2
0
        public static void RefreshXrmServices(IXrmRecordConfiguration xrmConfiguration, IApplicationController controller, XrmRecordService xrmRecordService = null)
        {
            controller.RegisterInstance <IXrmRecordConfiguration>(xrmConfiguration);
            var serviceFactory = controller.ResolveType <IOrganizationConnectionFactory>();

            xrmRecordService = xrmRecordService ?? new XrmRecordService(xrmConfiguration, serviceFactory, formService: new XrmFormService());
            xrmRecordService.XrmRecordConfiguration = xrmConfiguration;
            controller.RegisterInstance(xrmRecordService);
            LastXrmConfiguration = xrmConfiguration;

            var spawnConnectAsynch = !xrmConfiguration.UseXrmToolingConnector;

            if (xrmConfiguration.OrganizationUniqueName == null && !xrmConfiguration.UseXrmToolingConnector)
            {
                RefreshConnectionNotification(controller, "No Active Connection");
            }
            else if (!spawnConnectAsynch)
            {
                RefreshConnectionNotification(controller, string.Format("Connected To '{0}'", xrmConfiguration));
            }
            else if (controller.RunThreadsAsynch && spawnConnectAsynch)
            {
                controller.DoOnAsyncThread(() =>
                {
                    try
                    {
                        RefreshConnectionNotification(controller, $"Connecting To '{xrmConfiguration}'", isLoading: true);
                        var verify = xrmRecordService.VerifyConnection();
                        if (LastXrmConfiguration != xrmConfiguration)
                        {
                            return;
                        }
                        if (verify.IsValid)
                        {
                            RefreshConnectionNotification(controller, string.Format("Connected To '{0}'", xrmConfiguration));
                            var preLoadRecordTypes = xrmRecordService.GetAllRecordTypes();
                        }
                        else
                        {
                            RefreshConnectionNotification(controller, string.Format("Error Connecting To '{0}'", xrmConfiguration));
                        }
                    }
                    catch (Exception ex)
                    {
                        if (LastXrmConfiguration != xrmConfiguration)
                        {
                            return;
                        }
                        RefreshConnectionNotification(controller, ex.Message);
                        controller.ThrowException(ex);
                    }
                });
            }
        }
        public static void RefreshXrmServices(IXrmRecordConfiguration xrmConfiguration, IApplicationController controller)
        {
            controller.RegisterInstance <IXrmRecordConfiguration>(xrmConfiguration);
            var serviceConnection = new XrmRecordService(xrmConfiguration, controller.ResolveType <LogController>(), formService: new XrmFormService());

            controller.RegisterInstance(serviceConnection);
            LastXrmConfiguration = xrmConfiguration;
            if (xrmConfiguration.OrganizationUniqueName == null)
            {
                controller.AddNotification("XRMCONNECTION", "No Active Connection");
            }
            else if (controller.RunThreadsAsynch)
            {
                controller.DoOnAsyncThread(() =>
                {
                    try
                    {
                        controller.AddNotification("XRMCONNECTION", $"Connecting To '{xrmConfiguration}'", isLoading: true);
                        var verify = serviceConnection.VerifyConnection();
                        if (LastXrmConfiguration != xrmConfiguration)
                        {
                            return;
                        }
                        if (verify.IsValid)
                        {
                            controller.AddNotification("XRMCONNECTION", string.Format("Connected To '{0}'", xrmConfiguration));
                            var preLoadRecordTypes = serviceConnection.GetAllRecordTypes();
                        }
                        else
                        {
                            controller.AddNotification("XRMCONNECTION", string.Format("Error Connecting To '{0}'", xrmConfiguration));
                        }
                    }
                    catch (Exception ex)
                    {
                        if (LastXrmConfiguration != xrmConfiguration)
                        {
                            return;
                        }
                        controller.AddNotification("XRMCONNECTION", ex.Message);
                        controller.ThrowException(ex);
                    }
                });
            }
        }
        public static void VerifyPackageEntryRedirect(IXrmRecordConfiguration originalConnection, DialogViewModel dialog)
        {
            //okay we should have been directed to a connection entry
            var connectionEntryViewModel = dialog.Controller.UiItems[0] as ObjectEntryViewModel;
            var newConnection            = connectionEntryViewModel.GetObject() as SavedXrmRecordConfiguration;

            newConnection.AuthenticationProviderType = originalConnection.AuthenticationProviderType;
            newConnection.DiscoveryServiceAddress    = originalConnection.DiscoveryServiceAddress;
            newConnection.OrganizationUniqueName     = originalConnection.OrganizationUniqueName;
            newConnection.Domain   = originalConnection.Domain;
            newConnection.Username = originalConnection.Username;
            newConnection.Password = originalConnection.Password;
            newConnection.Name     = "RedirectScriptEntered";
            connectionEntryViewModel.SaveButtonViewModel.Invoke();
            //okay now we should be directed to the xrm package settings entry
            var packageSettingsEntryViewModel = dialog.Controller.UiItems[0] as ObjectEntryViewModel;
            var newPackageSettings            = packageSettingsEntryViewModel.GetObject() as XrmPackageSettings;

            newPackageSettings.SolutionObjectPrefix      = "FAKEIT";
            newPackageSettings.SolutionDynamicsCrmPrefix = "fake";
            packageSettingsEntryViewModel.SaveButtonViewModel.Invoke();

            //lets just verify the connections were saved as well
            var savedConnections = dialog.ApplicationController.ResolveType <ISavedXrmConnections>();

            Assert.IsTrue(savedConnections.Connections.Any(c => c.Name == "RedirectScriptEntered"));
            var appXrmRecordService = dialog.ApplicationController.ResolveType <XrmRecordService>();

            Assert.IsTrue(appXrmRecordService.XrmRecordConfiguration.ToString() == "RedirectScriptEntered");
            //var appXrmRecordConnection = dialog.ApplicationController.ResolveType<IXrmRecordConfiguration>();
            //Assert.IsTrue(appXrmRecordConnection.ToString() == "RedirectScriptEntered");
            var savedSetingsManager   = dialog.ApplicationController.ResolveType <ISettingsManager>();
            var savedXrmRecordService = savedSetingsManager.Resolve <XrmPackageSettings>();

            Assert.IsTrue(appXrmRecordService.XrmRecordConfiguration.ToString() == "RedirectScriptEntered");
            var savedXrmRecordConnection = savedSetingsManager.Resolve <XrmRecordConfiguration>();
        }