Ejemplo n.º 1
0
        // TODO: Swap TemplatingViewModel for a TemplatingViewModelFactory
        // TODO: Swap SettingsViewModel for a SettingsViewModelFactory
        public MainWindowViewModel(
            IDataController dataController,
            ITemplatingViewModel templatingViewModel,
            ISettingsViewModel settingsViewModel,
            ISettingsManager settingsManager,
            IWindowService windowService,
            IDispatcherHelper dispatcherHelper)
        {
            IntegrityCheck.IsNotNull(dataController);
            IntegrityCheck.IsNotNull(templatingViewModel);
            IntegrityCheck.IsNotNull(settingsViewModel);
            IntegrityCheck.IsNotNull(settingsManager);
            IntegrityCheck.IsNotNull(windowService);
            IntegrityCheck.IsNotNull(dispatcherHelper);

            // Save arguments
            m_DataController      = dataController;
            m_TemplatingViewModel = templatingViewModel;
            m_SettingsViewModel   = settingsViewModel;
            m_SettingsManager     = settingsManager;
            m_WindowService       = windowService;
            m_DispatcherHelper    = dispatcherHelper;

            // Initialise the state machine
            m_StateLock = new object();
            m_StateMgr  = new StateManager <MainWindowState>(this, typeof(Uninitialised));

            // Configure commands/event handlers
            InitialiseCommands();
            m_DataController.InitialisationComplete  += DataController_InitialisationComplete;
            m_DataController.GetCaptureComplete      += DataController_GetCaptureComplete;
            m_DataController.SaveTemplateComplete    += DataController_SaveTemplateComplete;
            m_TemplatingViewModel.UserActionRequired += TemplatingViewModel_UserActionRequired;
        }
Ejemplo n.º 2
0
        private double ParseValue(object value)
        {
            IntegrityCheck.IsNotNull(value);
            double val;
            bool   isValSuccessful = double.TryParse((string)value, out val);

            IntegrityCheck.IsTrue(isValSuccessful);
            return(val);
        }
            public override void OnEnteringState()
            {
                base.OnEnteringState();

                Outer.PromptText = m_PromptText;

                m_Identifier = StartAsyncOperation();
                IntegrityCheck.IsNotNull(m_Identifier);
            }
Ejemplo n.º 4
0
        // TODO: Note that there is a contract here, CaptureComplete SHALL follow, in a timely manner
        Guid IDataController.BeginGetCapture(ScannerType scannerType)
        {
            Log.DebugFormat("BeginGetCapture(scannterType={0}) called",
                            scannerType);
            IntegrityCheck.IsNotNull(scannerType);

            return(StartLogic((Guid guid, CancellationToken token) =>
                              StartCaptureTask(scannerType, guid, token)));
        }
        public TemplatingViewModel(IDispatcherHelper dispatcherHelper)
        {
            IntegrityCheck.IsNotNull(dispatcherHelper);

            m_DispatcherHelper = dispatcherHelper;

            m_StateLock = new object();
            Minutae     = new TrulyObservableCollection <MinutiaRecord>();
            m_StateMgr  = new StateManager <TemplatingState>(this, typeof(Uninitialised));
        }
Ejemplo n.º 6
0
            public override void OnEnteringState()
            {
                base.OnEnteringState();

                Outer.OnUserActionRequired(new UserActionRequiredEventArgs(SET_ANGLE_PROMPT));

                // Get the minutia that was placed in the previous step
                IntegrityCheck.AreNotEqual(0, Outer.Minutae.Count());
                m_Record = Outer.Minutae.Last();
                IntegrityCheck.IsNotNull(m_Record.Position);
            }
            public override void PositionUpdate(Point position)
            {
                IntegrityCheck.IsNotNull(position);

                lock (Outer.m_SelectedMinutiaLock)
                {
                    IntegrityCheck.IsNotNull(Outer.m_SelectedMinutia.HasValue);
                    // Set position
                    Outer.Minutae[Outer.m_SelectedMinutia.Value].Position = position;
                }
            }
Ejemplo n.º 8
0
        // TODO: Note that there is a contract here, InitialisedComplete SHALL follow, in a timely manner
        Guid IDataController.BeginInitialise(DataControllerConfig config)
        {
            Log.Debug("BeginInitialise(...) called.");
            IntegrityCheck.IsNotNull(config, "config");
            IntegrityCheck.IsNotNullOrEmpty(config.ApiKey, "config.ApiKey");
            IntegrityCheck.IsNotNullOrEmpty(config.UrlRoot, "config.UrlRoot");

            m_Config = config;
            m_TokenSourceLookup.Clear();

            return(StartLogic((Guid guid, CancellationToken token) =>
                              StartInitialiseTask(config, guid, token)));
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GetCaptureCompleteEventArgs"/> class in
        /// the case where the request was successful.
        /// </summary>
        /// <param name="capture">The capture.</param>
        /// <param name="requestId">The request unique identifier.</param>
        public GetCaptureCompleteEventArgs(CaptureInfo capture, Guid requestId, DataRequestResult result)
        {
            IntegrityCheck.IsNotNull(requestId);
            IntegrityCheck.IsNotNull(result);
            if (result == DataRequestResult.Success)
            {
                IntegrityCheck.IsNotNull(capture);
            }

            m_Capture   = capture;
            m_RequestId = requestId;
            m_Result    = result;
        }
Ejemplo n.º 10
0
        public StateManager(ViewModel viewModel, Type initialStateType)
        {
            IntegrityCheck.IsNotNull(viewModel);

            m_ViewModel = viewModel;

            // Instantiate all concrete states into a list for transitioning to.
            m_States = new Dictionary <Type, T>();
            foreach (Type type in Assembly.GetAssembly(typeof(T)).GetTypes()
                     .Where(myType =>
                            myType.IsClass && !myType.IsAbstract && myType.IsSubclassOf(typeof(T))))
            {
                m_States.Add(type, (T)Activator.CreateInstance(type, m_ViewModel));
            }

            // Transition to the initial state.
            TransitionTo(initialStateType);
        }
Ejemplo n.º 11
0
        private T ToState(Type stateType)
        {
            IntegrityCheck.IsTrue(
                typeof(T).IsAssignableFrom(stateType),
                "Supplied type doesn't derive from {0}", typeof(T).Name);
            IntegrityCheck.IsFalse(
                stateType.IsAbstract,
                "Cannot transition to abstract state {0}", stateType.Name);

            T    state;
            bool isFound = m_States.TryGetValue(stateType, out state);

            IntegrityCheck.IsTrue(isFound, "State {0} not found in m_States", stateType.Name);
            IntegrityCheck.IsNotNull(
                state,
                "State {0} found in m_States, but value was null",
                stateType.Name);

            return(state);
        }
Ejemplo n.º 12
0
        void IDataController.AbortRequest(Guid guid)
        {
            Log.DebugFormat("AbortRequest(guid={0}) called.", guid);
            IntegrityCheck.IsNotNull(guid);

            // Attempt to lookup the token.
            CancellationTokenSource tokenSource;
            bool isSuccessful = m_TokenSourceLookup.TryGetValue(guid, out tokenSource);

            if (isSuccessful)
            {
                // Request cancellation.
                IntegrityCheck.IsNotNull(tokenSource);
                tokenSource.Cancel();
                m_TokenSourceLookup.Remove(guid);
            }
            else
            {
                // TODO: What to do if Guid doesn't correspond to a current request?
                Log.WarnFormat("Cancellation of request (guid={0}) failed, token no longer exists.",
                               guid);
            }
        }
Ejemplo n.º 13
0
            protected override void OnOperationComplete(GetCaptureCompleteEventArgs e)
            {
                // We have recieved a response from our request.
                // Indicate we are no longer loading.

                switch (e.Result)
                {
                case DataRequestResult.Success:
                    IntegrityCheck.IsNotNull(e.Capture);

                    Outer.PromptText = "Capture loaded";
                    Outer.m_TemplatingViewModel.BeginTemplating(e.Capture);
                    TransitionTo(typeof(Templating));
                    break;

                case DataRequestResult.Failed:
                    // No capture was obtained.
                    Outer.PromptText = "No capture matching the criteria obtained.";
                    Log.DebugFormat(
                        "Capture request returned Failed response.",
                        Outer.FilteredScannerType);
                    TransitionTo(typeof(Idle));
                    break;

                case DataRequestResult.TaskFailed:
                    // No capture was obtained.
                    Outer.PromptText = "App failed to carry out capture request.";
                    Log.ErrorFormat(
                        "Capture request returned TaskFailed response.",
                        Outer.FilteredScannerType);
                    TransitionTo(typeof(Idle));
                    break;

                default:
                    throw IntegrityCheck.FailUnexpectedDefault(e.Result);
                }
            }
Ejemplo n.º 14
0
 public State(ViewModel outer)
 {
     IntegrityCheck.IsNotNull(outer);
     m_Outer = outer;
 }
Ejemplo n.º 15
0
 private static void CheckElementNotNull(XElement el, string tag)
 {
     IntegrityCheck.IsNotNull(el,
                              "Capture was missing '{0}' element.", tag);
 }