Exemplo n.º 1
0
        /// <summary>
        /// Create Simple Crate Manifest used for polling process
        /// </summary>
        /// <param name="stat"></param>
        /// <returns></returns>
        public static StatXItemCM MapToStatItemCrateManifest(BaseStatDTO stat)
        {
            var result = new StatXItemCM()
            {
                Id                  = stat.Id,
                Title               = stat.Title,
                VisualType          = stat.VisualType,
                LastUpdatedDateTime = stat.LastUpdatedDateTime.ToString(),
            };

            var statDTO = stat as GeneralStatDTO;

            if (statDTO != null)
            {
                result.Value        = statDTO.Value;
                result.CurrentIndex = statDTO.CurrentIndex;
            }
            else
            {
                result.CurrentIndex   = ((GeneralStatWithItemsDTO)stat).CurrentIndex;
                result.StatValueItems = ((GeneralStatWithItemsDTO)stat).Items.Select(x => new StatValueItemDTO()
                {
                    Name    = x.Name,
                    Value   = x.Value,
                    Checked = x.Checked,
                }).ToList();
            }

            return(result);
        }
Exemplo n.º 2
0
        public async Task CreateStat(StatXAuthDTO statXAuthDTO, string groupId, BaseStatDTO statDTO)
        {
            try
            {
                var uri = new Uri(StatXBaseApiUrl + $"/groups/{groupId}/stats");

                string json = JsonConvert.SerializeObject(statDTO, Formatting.Indented, new JsonSerializerSettings {
                    ContractResolver = new DynamicContractResolver(statDTO.DynamicJsonIgnoreProperties)
                });

                var response = await _restfulServiceClient.PostAsync(uri, (HttpContent) new StringContent(json), null, GetStatxAPIHeaders(statXAuthDTO));

                var jObject = JObject.Parse(response);

                CheckForExistingErrors(jObject);
            }
            catch (RestfulServiceException exception)
            {
                var    jObject = JObject.Parse(exception.ResponseMessage);
                JToken errorsToken;
                if (jObject.TryGetValue("errors", out errorsToken))
                {
                    if (errorsToken is JArray)
                    {
                        var firstError = (JObject)errorsToken.First;

                        throw new ApplicationException($"StatX request error: {firstError["message"]?.ToString()}");
                    }
                }
            }
        }
Exemplo n.º 3
0
        private static BaseStatDTO ExtractSingleStatFromResponse(JObject jObject)
        {
            //check for items
            JToken      itemsToken;
            BaseStatDTO stat = null;

            if (jObject.TryGetValue("items", out itemsToken))
            {
                //special case for stats that contains item objects
                stat = new GeneralStatWithItemsDTO()
                {
                    Id           = jObject["id"]?.ToString(),
                    Title        = jObject["title"]?.ToString(),
                    VisualType   = jObject["visualType"]?.ToString(),
                    Notes        = jObject["notes"]?.ToString(),
                    CurrentIndex = jObject["currentIndex"] != null?int.Parse(jObject["currentIndex"].ToString()) : 0,
                                       LastUpdatedDateTime = jObject["lastUpdatedDateTime"] != null?DateTime.Parse(jObject["lastUpdatedDateTime"].ToString()) : (DateTime?)null,
                                                                 NotesLastUpdatedDateTime = jObject["notesLastUpdatedDateTime"] != null?DateTime.Parse(jObject["notesLastUpdatedDateTime"].ToString()) : (DateTime?)null,
                };
                foreach (var valueItem in itemsToken)
                {
                    if (valueItem is JValue)
                    {
                        ((GeneralStatWithItemsDTO)stat).Items.Add(new StatItemValueDTO()
                        {
                            Name  = valueItem.ToString(),
                            Value = valueItem.ToString()
                        });
                    }
                    else
                    {
                        ((GeneralStatWithItemsDTO)stat).Items.Add(new StatItemValueDTO()
                        {
                            Name    = valueItem["name"]?.ToString(),
                            Value   = valueItem["value"]?.ToString(),
                            Checked = valueItem["checked"] != null && bool.Parse(valueItem["checked"].ToString())
                        });
                    }
                }
            }
            else
            {
                stat = new GeneralStatDTO()
                {
                    Id           = jObject["id"]?.ToString(),
                    Title        = jObject["title"]?.ToString(),
                    VisualType   = jObject["visualType"]?.ToString(),
                    Value        = jObject["value"]?.ToString(),
                    Notes        = jObject["notes"]?.ToString(),
                    CurrentIndex = jObject["currentIndex"] != null?int.Parse(jObject["currentIndex"].ToString()) : 0,
                                       LastUpdatedDateTime = jObject["lastUpdatedDateTime"] != null?DateTime.Parse(jObject["lastUpdatedDateTime"].ToString()) : (DateTime?)null,
                                                                 NotesLastUpdatedDateTime = jObject["notesLastUpdatedDateTime"] != null?DateTime.Parse(jObject["notesLastUpdatedDateTime"].ToString()) : (DateTime?)null,
                };
            }

            stat.DynamicJsonIgnoreProperties = new[] { "visualType" };

            return(stat);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Adds the specified baseStat to the given character.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="baseStat">The base stat.</param>
 /// <param name="id">The id.</param>
 /// <exception cref="NotImplementedException"></exception>
 internal static void Add(DndDmHelperContext context, BaseStatDTO baseStat, TemplateCharacter character)
 {
     context.Add(new TemplateCharacterBaseStat()
     {
         BaseStatID = baseStat.ID,
         Character  = character,
         Value      = baseStat.Value
     });
 }
Exemplo n.º 5
0
 internal static BaseStatModel GeneralBaseStatModelFromDTO(BaseStatDTO baseStat)
 {
     return(new BaseStatModel()
     {
         ID = baseStat.ID,
         Name = baseStat.Name,
         Value = baseStat.Value,
         Default = baseStat.Default,
         LastEdited = baseStat.LastEdited
     });
 }
Exemplo n.º 6
0
        /// <summary>
        /// Populate values into stat properties for all RenderedUi properties in the Activity
        /// </summary>
        /// <param name="stat"></param>
        /// <param name="statProperties"></param>
        private static void PopulateStatObject(BaseStatDTO stat, List <KeyValueDTO> statProperties)
        {
            stat.LastUpdatedDateTime      = DateTime.UtcNow;
            stat.NotesLastUpdatedDateTime = DateTime.UtcNow;

            var statPropertyInfo = stat.GetType().GetProperties().Where(prop => prop.IsDefined(typeof(RenderUiPropertyAttribute), false)).ToList();

            foreach (var property in statPropertyInfo)
            {
                var payloadItem = statProperties.FirstOrDefault(x => x.Key == property.Name);
                if (payloadItem != null)
                {
                    property.SetValue(stat, Convert.ChangeType(payloadItem.Value, property.PropertyType), null);
                }
            }
        }
Exemplo n.º 7
0
 internal static IEnumerable <BaseStatDTO> GetAll(DndDmHelperContext context)
 {
     return(context.BaseStats.Select(e => BaseStatDTO.GenerateDTOFromEntity(e)));
 }