/// <summary>
        /// Used to create the metadata type instance for a corresponding Box File Id.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="metadata"></param>
        /// <param name="typeInstance"></param>
        /// <returns>A BoxMetadata object that includes key:value pairs defined by a user or application. 
        /// If the properties instance already exists, a 409 HTTP status code of conflict will be returned and the update method should be used</returns>
        public async Task<BoxMetadata> CreateMetadata(string id, Dictionary<string,string> metadata, string typeInstance = DefaultTypeInstance)
        {
            id.ThrowIfNullOrWhiteSpace("id");
            metadata.ThrowIfNull("metadata");

            BoxRequest request = new BoxRequest(new Uri(Constants.BoxApiUriString + string.Format(CultureInfo.InvariantCulture, MetadataEndpointPath, id, typeInstance)))
                .Method(RequestMethod.Post);

            request.Payload = _converter.Serialize(metadata);
            request.ContentType = JsonContentType;

            IBoxResponse<BoxMetadata> response = await ToResponseAsync<BoxMetadata>(request).ConfigureAwait(false);

            return response.ResponseObject;
        }
Example #2
0
        /// <summary>
        /// Gets the time required to train all the prerequisites
        /// </summary>
        /// <param name="src">The source.</param>
        /// <param name="alreadyCountedList">The already counted list.</param>
        /// <param name="isCurrentlyTraining">if set to <c>true</c> [is currently training].</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">src or alreadyCountedList</exception>
        public static TimeSpan GetTotalTrainingTime(this IEnumerable<SkillLevel> src, Dictionary<Skill, Int64> alreadyCountedList,
            ref bool isCurrentlyTraining)
        {
            src.ThrowIfNull(nameof(src));

            alreadyCountedList.ThrowIfNull(nameof(alreadyCountedList));

            TimeSpan result = TimeSpan.Zero;
            foreach (SkillLevel item in src)
            {
                Skill skill = item.Skill;
                isCurrentlyTraining |= skill.IsTraining;

                // Gets the number of points we're starting from
                Int64 fromPoints = skill.SkillPoints;
                if (alreadyCountedList.ContainsKey(skill))
                    fromPoints = alreadyCountedList[skill];

                // Gets the number of points we're targeting
                Int64 toPoints = skill.GetLeftPointsRequiredToLevel(item.Level);
                if (fromPoints < toPoints)
                    result += skill.GetTimeSpanForPoints(toPoints - fromPoints);

                // Updates the alreadyCountedList
                alreadyCountedList[skill] = Math.Max(fromPoints, toPoints);

                // Recursive
                if (fromPoints < toPoints)
                    result += skill.Prerequisites.GetTotalTrainingTime(alreadyCountedList, ref isCurrentlyTraining);
            }
            return result;
        }