Esempio n. 1
0
            protected override object StartAsyncOperation()
            {
                // Initialise the DataController so that we can fetch images.
                DataControllerConfig config = new DataControllerConfig(
                    (string)Outer.m_SettingsManager.GetCurrentSetting(Setting.ApiKey),
                    (string)Outer.m_SettingsManager.GetCurrentSetting(Setting.RootUrl));

                return(Outer.m_DataController.BeginInitialise(config));
            }
        protected override void StartInitialiseTask(DataControllerConfig config, Guid guid, CancellationToken token)
        {
            // Create client
            m_RestClient = new RestClient(Config.UrlRoot);

            // Construct a request for a token
            RestRequest request = new RestRequest(API_KEY_RESOURCE, Method.GET);

            request.AddParameter(API_KEY_PARAMETER, config.ApiKey);

            // Begin the request
            ResourceRequest(
                request,
                (ApiKey response) =>
            {
                m_Token = response.Token;
                OnInitialisationComplete(new InitialisationCompleteEventArgs(InitialisationResult.Initialised, guid, DataRequestResult.Success));
            },
                () => OnInitialisationComplete(new InitialisationCompleteEventArgs(InitialisationResult.Error, guid, DataRequestResult.Failed)));
        }
Esempio n. 3
0
        protected override void StartInitialiseTask(DataControllerConfig config, Guid guid, CancellationToken token)
        {
            // Define and run the task, passing in the token.
            Task initialiseTask = Task.Run(() =>
            {
                Log.Debug("Initialise task running.");
                // Connect to SQlite.
                SQLiteConnection dbConnection = new SQLiteConnection(
                    String.Format(CONNECTION_STRING, SQLITE_DATABASE));

                // Set the LINQ data context to the database connection.
                m_Database = new SimPrintsDb(dbConnection);

                // Obtain image files on local machine, to be matched with database entries.
                m_ImageFiles = GetImageFiles(IMAGES_FILE_PATH);
                if (m_ImageFiles != null &&
                    m_ImageFiles.Count() > 0)
                {
                    m_State = InitialisationResult.Initialised;
                }
                else
                {
                    Log.Error("Failed to get image files.");
                    m_State = InitialisationResult.Error;
                }

                OnInitialisationComplete(
                    new InitialisationCompleteEventArgs(m_State, guid, DataRequestResult.Success));
            }, token);

            // Raise the GetCaptureComplete event in the case where the Task faults.
            initialiseTask.ContinueWith((Task t) =>
            {
                if (t.IsFaulted)
                {
                    Log.Error("Failed initialise controller: " + t.Exception.Message, t.Exception);
                    OnInitialisationComplete(new InitialisationCompleteEventArgs(
                                                 InitialisationResult.Uninitialised, guid, DataRequestResult.TaskFailed));
                }
            });
        }
Esempio n. 4
0
 protected override void StartInitialiseTask(DataControllerConfig config, Guid guid, CancellationToken token)
 {
     // TODO: determine if it is possible to leave the user field empty
     m_ClientFactory.BeginGetClient(APP_SECRETS, API_CONTEXTS, "");
 }