Пример #1
0
        /// Accessor for a specific entry in the database
        /// @param primaryKey the key used to lookup the entry in the database
        protected async Task <DatabaseItem> GetEntryByKey(string primaryKey)
        {
            var getRequest = new GetItemRequest
            {
                TableName = tableName,
                Key       = new Dictionary <string, AttributeValue>
                {
                    { primaryPartitionKey, new AttributeValue {
                          S = primaryKey
                      } }
                }
            };

            DatabaseItem item = new DatabaseItem();

            try
            {
                var response = await client.GetItemAsync(getRequest);

                if (response.IsItemSet)
                {
                    item = response.Item;
                }
            }
            catch (Exception e)
            {
                log.WARN("DatabaseClient", "GetEntryByKey(string)", "EXCEPTION: " + e.Message);
            }

            return(item);
        }
Пример #2
0
        /// <summary>
        /// Updates this object with the values in the sessionAttributeDict
        /// </summary>
        /// <param name="sessionAttributeDict">Dictionary whose keys match the public members of this class</param>
        public void UpdateSessionAttributes(Dictionary <string, object> sessionAttributeDict)
        {
            SessionAttributes updatedSessionAttributes;

            try
            {
                updatedSessionAttributes = JsonConvert.DeserializeObject <SessionAttributes>(JsonConvert.SerializeObject(sessionAttributeDict));
            }
            catch (Exception e)
            {
                logger?.WARN("SessionAttributes", "UpdateSessionAttributes", "Failed to update SessionAttributes. " + e.Message);
                return;
            }

            CurrentWord         = updatedSessionAttributes.CurrentWord;
            SessionState        = updatedSessionAttributes.SessionState;
            LessonType          = updatedSessionAttributes.LessonType;
            LessonMode          = updatedSessionAttributes.LessonMode;
            LessonSkill         = updatedSessionAttributes.LessonSkill;
            Schedule            = updatedSessionAttributes.Schedule;
            WordsToRead         = updatedSessionAttributes.WordsToRead;
            TotalWordsInSession = updatedSessionAttributes.TotalWordsInSession;
            Attempts            = updatedSessionAttributes.Attempts;
        }