Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileDevicesEditor"/> class.
        /// </summary>
        /// <param name="synchronizationService">The synchronization service to be used
        /// for manipulating devices at the tracking service.</param>
        /// <param name="resourceProvider">The instance of resource provider for obtaining
        /// messages.</param>
        /// <param name="workingStatusController">The instance of the controller to be used
        /// for managing application status.</param>
        /// <param name="exceptionHandler">The exception handler for tracking service
        /// related errors.</param>
        /// <exception cref="ArgumentNullException"><paramref name="synchronizationService"/>,
        /// <paramref name="resourceProvider"/>, <paramref name="workingStatusController"/>,
        /// <paramref name="exceptionHandler"/> or <paramref name="project"/> is a null
        /// reference.</exception>
        public MobileDevicesEditor(
            ISynchronizationService synchronizationService,
            IWorkingStatusController workingStatusController,
            IExceptionHandler exceptionHandler,
            IProject project)
        {
            if (synchronizationService == null)
            {
                throw new ArgumentNullException("synchronizationService");
            }

            if (workingStatusController == null)
            {
                throw new ArgumentNullException("workingStatusController");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            _synchronizationService  = synchronizationService;
            _workingStatusController = workingStatusController;
            _exceptionHandler        = exceptionHandler;
            _project = project;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="MobileDevicesEditor"/> class.
        /// </summary>
        /// <param name="synchronizationService">The synchronization service to be used
        /// for manipulating devices at the tracking service.</param>
        /// <param name="resourceProvider">The instance of resource provider for obtaining
        /// messages.</param>
        /// <param name="workingStatusController">The instance of the controller to be used
        /// for managing application status.</param>
        /// <param name="exceptionHandler">The exception handler for tracking service
        /// related errors.</param>
        /// <exception cref="ArgumentNullException"><paramref name="synchronizationService"/>,
        /// <paramref name="resourceProvider"/>, <paramref name="workingStatusController"/>,
        /// <paramref name="exceptionHandler"/> or <paramref name="project"/> is a null
        /// reference.</exception>
        public MobileDevicesEditor(
            ISynchronizationService synchronizationService,
            IWorkingStatusController workingStatusController,
            IExceptionHandler exceptionHandler,
            IProject project)
        {
            if (synchronizationService == null)
            {
                throw new ArgumentNullException("synchronizationService");
            }

            if (workingStatusController == null)
            {
                throw new ArgumentNullException("workingStatusController");
            }

            if (exceptionHandler == null)
            {
                throw new ArgumentNullException("exceptionHandler");
            }

            if (project == null)
            {
                throw new ArgumentNullException("project");
            }

            _synchronizationService = synchronizationService;
            _workingStatusController = workingStatusController;
            _exceptionHandler = exceptionHandler;
            _project = project;
        }
        /// <summary>
        /// Initializes a new instance of the LicensePageModel class.
        /// </summary>
        /// <param name="servers">Collection of servers to provide separate
        /// authentication for.</param>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        /// <param name="uriNavigator">The reference to the object to be used
        /// for navigating to URI's.</param>
        public LicensePageModel(
            IEnumerable <AgsServer> servers,
            IMessenger messenger,
            IWorkingStatusController workingStatusController,
            IUriNavigator uriNavigator,
            ILicenseManager licenseManager)
        {
            Debug.Assert(servers != null);
            Debug.Assert(servers.All(server => server != null));
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);
            Debug.Assert(licenseManager != null);

            _licenseManager           = licenseManager;
            _licenseExpirationChecker = _licenseManager.LicenseExpirationChecker;

            var items = new ObservableCollection <LoginViewModelBase>();

            var licensingViewModel = new LicensingViewModel(
                messenger,
                workingStatusController,
                uriNavigator,
                licenseManager);

            this.RequiresExpirationWarning      = licensingViewModel.RequiresExpirationWarning;
            licensingViewModel.PropertyChanged += delegate
            {
                this.RequiresExpirationWarning = licensingViewModel.RequiresExpirationWarning;
                _UpdateCompletedState();
            };

            items.Add(licensingViewModel);

            _servers = servers.ToList();
            foreach (var server in _servers)
            {
                items.Add(new ArcGisServerLoginViewModel(
                              server,
                              messenger,
                              workingStatusController));
                server.StateChanged += delegate
                {
                    _UpdateCompletedState();
                };
            }

            this.LoginViewModels = new ReadOnlyObservableCollection <LoginViewModelBase>(items);
            _UpdateCompletedState();
            _UpdateLoggedInState();

            foreach (var vm in this.LoginViewModels)
            {
                vm.LoginState.LoginViewHost = this;
                vm.PropertyChanged         += delegate
                {
                    _UpdateLoggedInState();
                };
            }
        }
        /// <summary>
        /// Initializes a new instance of the LicensingViewModel class.
        /// </summary>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        /// <param name="uriNavigator">The reference to the object to be used
        /// for navigating to URI's.</param>
        /// <param name="licenseManager">The reference to the license manager
        /// object.</param>
        public LicensingViewModel(
            IMessenger messenger,
            IWorkingStatusController workingStatusController,
            IUriNavigator uriNavigator,
            ILicenseManager licenseManager)
        {
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);
            Debug.Assert(uriNavigator != null);
            Debug.Assert(licenseManager != null);

            _licenseManager           = licenseManager;
            _licenseExpirationChecker = licenseManager.LicenseExpirationChecker;
            _messenger = messenger;
            _workingStatusController = workingStatusController;
            _uriNavigator            = uriNavigator;

            _licensePageCommands = new LicensePageCommands()
            {
                CreateAccount = _CreateUrlNavigationCommand(
                    _licenseManager.LicenseComponent.CreateAccountURL,
                    _uriNavigator),
                RecoverCredentials = _CreateUrlNavigationCommand(
                    _licenseManager.LicenseComponent.RecoverCredentialsURL,
                    _uriNavigator),
                UpgradeLicense = _CreateUrlNavigationCommand(
                    _licenseManager.LicenseComponent.UpgradeLicenseURL,
                    _uriNavigator),
            };

            this.LicenseActivationStatus = _licenseManager.LicenseActivationStatus;
            this.LicenseState            = this.LicenseActivationStatus == LicenseActivationStatus.Activated ?
                                           AgsServerState.Authorized : AgsServerState.Unauthorized;
            _UpdateExpirationWarningDisplayState();

            foreach (var item in EnumHelpers.GetValues <AgsServerState>())
            {
                this.RegisterHeader(
                    item,
                    _licenseManager.LicenseComponent.LoginPrompt);
            }

            _CreateLoginState();
            _CreateConnectedState();
            _CreateNotConnectedState();

            this.LicensingNotes = _CreateLicensingNotes(
                _licenseManager.LicenseComponent.LicensingNotes);
            this.TroubleshootingNotes = _CreateTroubleshootingNotes(
                _licenseManager.LicenseComponent.TroubleshootingNotes);

            _stateFactories = new Dictionary <LicenseActivationStatus, Func <LicenseActivationViewState> >()
            {
                {
                    LicenseActivationStatus.None,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState       = this.LoginState,
                        InformationViewState = (object)null,
                    }
                },
                {
                    LicenseActivationStatus.Activated,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState       = this.ConnectedState,
                        InformationViewState = _CreateActivatedState(),
                    }
                },
                {
                    LicenseActivationStatus.Expired,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState       = this.LoginState,
                        InformationViewState = _CreateExpiredState(),
                    }
                },
                {
                    LicenseActivationStatus.WrongCredentials,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState       = this.LoginState,
                        InformationViewState = _CreateWrongCredentialsState(),
                    }
                },
                {
                    LicenseActivationStatus.NoSubscription,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState       = this.LoginState,
                        InformationViewState = _CreateNoSubscriptionState(),
                    }
                },
                {
                    LicenseActivationStatus.Failed,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState       = this.NotConnectedState,
                        InformationViewState = (object)null,
                    }
                },
            };
        }
        /// <summary>
        /// Initializes a new instance of the ArcGisServerLoginViewModel class.
        /// </summary>
        /// <param name="server">The server to provide authentication for.</param>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        public ArcGisServerLoginViewModel(
            AgsServer server,
            IMessenger messenger,
            IWorkingStatusController workingStatusController)
        {
            Debug.Assert(server != null);
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);

            _server = server;
            _server.StateChanged += _ServerStateChanged;

            this.LicenseState = server.State;
            this.RegisterHeader(
                AgsServerState.Unauthorized,
                App.Current.GetString("LoginToServerString", _server.Title));

            _messenger = messenger;
            _workingStatusController = workingStatusController;

            var licensePageCommands = new LicensePageCommands()
            {
                CreateAccount      = null,
                RecoverCredentials = null,
                UpgradeLicense     = null,
            };

            this.LoginState = new LoginStateViewModel(
                licensePageCommands,
                _ExecuteLogin);

            var licenseInfoText = EnumerableEx.Return(ApplyStyle(new FlowDocument(
                                                                     new Paragraph()
            {
                Inlines =
                {
                    new Run(App.Current.GetString("LoggedToServerString", _server.Title)),
                    new Run(NEW_LINE),
                    new Run(_server.Description)
                },
            }
                                                                     )));

            this.ConnectedState = new ConnectedStateViewModel(
                licensePageCommands,
                licenseInfoText)
            {
                SwitchUserCommand          = new DelegateCommand(
                    _ => this.LicenseState = AgsServerState.Unauthorized),
            };

            var connectionFailureInfo = ApplyStyle(new FlowDocument(
                                                       new Paragraph(
                                                           new Run(App.Current.GetString(
                                                                       "ServerIsUnavailableString",
                                                                       _server.Title)
                                                                   )
                                                           )
                                                       ));

            this.NotConnectedState = new NotConnectedStateViewModel()
            {
                ConnectionFailureInfo = connectionFailureInfo,
            };
        }
        /// <summary>
        /// Initializes a new instance of the LicensePageModel class.
        /// </summary>
        /// <param name="servers">Collection of servers to provide separate
        /// authentication for.</param>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        /// <param name="uriNavigator">The reference to the object to be used
        /// for navigating to URI's.</param>
        public LicensePageModel(
            IEnumerable<AgsServer> servers,
            IMessenger messenger,
            IWorkingStatusController workingStatusController,
            IUriNavigator uriNavigator,
            ILicenseManager licenseManager)
        {
            Debug.Assert(servers != null);
            Debug.Assert(servers.All(server => server != null));
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);
            Debug.Assert(licenseManager != null);

            _licenseManager = licenseManager;
            _licenseExpirationChecker = _licenseManager.LicenseExpirationChecker;

            var items = new ObservableCollection<LoginViewModelBase>();

            var licensingViewModel = new LicensingViewModel(
                messenger,
                workingStatusController,
                uriNavigator,
                licenseManager);
            this.RequiresExpirationWarning = licensingViewModel.RequiresExpirationWarning;
            licensingViewModel.PropertyChanged += delegate
            {
                this.RequiresExpirationWarning = licensingViewModel.RequiresExpirationWarning;
                _UpdateCompletedState();
            };

            items.Add(licensingViewModel);

            _servers = servers.ToList();
            foreach (var server in _servers)
            {
                items.Add(new ArcGisServerLoginViewModel(
                    server,
                    messenger,
                    workingStatusController));
                server.StateChanged += delegate
                {
                    _UpdateCompletedState();
                };
            }

            this.LoginViewModels = new ReadOnlyObservableCollection<LoginViewModelBase>(items);
            _UpdateCompletedState();
            _UpdateLoggedInState();

            foreach (var vm in this.LoginViewModels)
            {
                vm.LoginState.LoginViewHost = this;
                vm.PropertyChanged += delegate
                {
                    _UpdateLoggedInState();
                };
            }
        }
        /// <summary>
        /// Initializes a new instance of the LicensingViewModel class.
        /// </summary>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        /// <param name="uriNavigator">The reference to the object to be used
        /// for navigating to URI's.</param>
        /// <param name="licenseManager">The reference to the license manager
        /// object.</param>
        public LicensingViewModel(
            IMessenger messenger,
            IWorkingStatusController workingStatusController,
            IUriNavigator uriNavigator,
            ILicenseManager licenseManager)
        {
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);
            Debug.Assert(uriNavigator != null);
            Debug.Assert(licenseManager != null);

            _licenseManager = licenseManager;
            _licenseExpirationChecker = licenseManager.LicenseExpirationChecker;
            _messenger = messenger;
            _workingStatusController = workingStatusController;
            _uriNavigator = uriNavigator;

            _licensePageCommands = new LicensePageCommands()
            {
                CreateAccount = _CreateUrlNavigationCommand(
                    _licenseManager.LicenseComponent.CreateAccountURL,
                    _uriNavigator),
                RecoverCredentials = _CreateUrlNavigationCommand(
                    _licenseManager.LicenseComponent.RecoverCredentialsURL,
                    _uriNavigator),
                UpgradeLicense = _CreateUrlNavigationCommand(
                    _licenseManager.LicenseComponent.UpgradeLicenseURL,
                    _uriNavigator),
            };

            this.LicenseActivationStatus = _licenseManager.LicenseActivationStatus;
            this.LicenseState = this.LicenseActivationStatus == LicenseActivationStatus.Activated ?
                AgsServerState.Authorized : AgsServerState.Unauthorized;
            _UpdateExpirationWarningDisplayState();

            foreach (var item in EnumHelpers.GetValues<AgsServerState>())
            {
                this.RegisterHeader(
                    item,
                    _licenseManager.LicenseComponent.LoginPrompt);
            }

            _CreateLoginState();
            _CreateConnectedState();
            _CreateNotConnectedState();

            this.LicensingNotes = _CreateLicensingNotes(
                _licenseManager.LicenseComponent.LicensingNotes);
            this.TroubleshootingNotes = _CreateTroubleshootingNotes(
                _licenseManager.LicenseComponent.TroubleshootingNotes);

            _stateFactories = new Dictionary<LicenseActivationStatus, Func<LicenseActivationViewState>>()
            {
                {
                    LicenseActivationStatus.None,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState = this.LoginState,
                        InformationViewState = (object)null,
                    }
                },
                {
                    LicenseActivationStatus.Activated,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState = this.ConnectedState,
                        InformationViewState = _CreateActivatedState(),
                    }
                },
                {
                    LicenseActivationStatus.Expired,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState = this.LoginState,
                        InformationViewState = _CreateExpiredState(),
                    }
                },
                {
                    LicenseActivationStatus.WrongCredentials,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState = this.LoginState,
                        InformationViewState = _CreateWrongCredentialsState(),
                    }
                },
                {
                    LicenseActivationStatus.NoSubscription,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState = this.LoginState,
                        InformationViewState = _CreateNoSubscriptionState(),
                    }
                },
                {
                    LicenseActivationStatus.Failed,
                    () => new LicenseActivationViewState
                    {
                        LoginViewState = this.NotConnectedState,
                        InformationViewState = (object)null,
                    }
                },
            };
        }
        /// <summary>
        /// Initializes a new instance of the ArcGisServerLoginViewModel class.
        /// </summary>
        /// <param name="server">The server to provide authentication for.</param>
        /// <param name="messenger">The messenger object to be used for
        /// notifications.</param>
        /// <param name="workingStatusController">The object to be used for
        /// managing application working status.</param>
        public ArcGisServerLoginViewModel(
            AgsServer server,
            IMessenger messenger,
            IWorkingStatusController workingStatusController)
        {
            Debug.Assert(server != null);
            Debug.Assert(messenger != null);
            Debug.Assert(workingStatusController != null);

            _server = server;
            _server.StateChanged += _ServerStateChanged;

            this.LicenseState = server.State;
            this.RegisterHeader(
                AgsServerState.Unauthorized,
                App.Current.GetString("LoginToServerString", _server.Title));

            _messenger = messenger;
            _workingStatusController = workingStatusController;

            var licensePageCommands = new LicensePageCommands()
            {
                CreateAccount = null,
                RecoverCredentials = null,
                UpgradeLicense = null,
            };

            this.LoginState = new LoginStateViewModel(
                licensePageCommands,
                _ExecuteLogin);

            var licenseInfoText = EnumerableEx.Return(ApplyStyle(new FlowDocument(
                new Paragraph()
                {
                    Inlines =
                    {
                        new Run(App.Current.GetString("LoggedToServerString", _server.Title)),
                        new Run(NEW_LINE),
                        new Run(_server.Description)
                    },
                }
            )));

            this.ConnectedState = new ConnectedStateViewModel(
                licensePageCommands,
                licenseInfoText)
            {
                SwitchUserCommand = new DelegateCommand(
                    _ => this.LicenseState = AgsServerState.Unauthorized),
            };

            var connectionFailureInfo = ApplyStyle(new FlowDocument(
                new Paragraph(
                    new Run(App.Current.GetString(
                        "ServerIsUnavailableString",
                        _server.Title)
                    )
                )
            ));

            this.NotConnectedState = new NotConnectedStateViewModel()
            {
                ConnectionFailureInfo = connectionFailureInfo,
            };
        }