示例#1
0
        public async Task <IActionResult> OnPostGetUserGroupResourceUsageReportAsync()
        {
            try
            {
                string username = "******";
                string password = "******";

                //AuthenticateUserPassword
                sb.AppendLine(String.Format("username: {0}, password: {1}", username, password));
                string sessionCode = await AuthenticateUserPasswordAsync(username, password);

                sb.AppendLine(String.Format("sessionCode: {0}", sessionCode));

                //GetUserGroupResourceUsageReport
                sb.AppendLine(String.Format("Getting report for Group: {0}", 1));
                UserGroupResourceUsageReportExt userGroupUsageReport = await GetUserGroupResourceUsageReportAsync(1, new DateTime(2019, 6, 1), DateTime.UtcNow, sessionCode); //TODO GET USER ID and DATE TIME

                //sb.AppendLine(String.Format(userGroupUsageReport.ToString()));

                ResponseContent = sb.ToString();
            }
            catch (Exception e)
            {
                ResponseContent = e.Message;
            }

            return(Page());
        }
示例#2
0
        private static async Task <UserGroupResourceUsageReportExt> GetUserGroupResourceUsageReportAsync(long groupId, DateTime startTime, DateTime endTime, string sessionCode)
        {
            var client  = new RestClient(baseUrl);
            var request = new RestRequest("JobReporting/GetUserGroupResourceUsageReport", Method.Post)
            {
                RequestFormat = DataFormat.Json
            }.AddJsonBody(
                new GetUserGroupResourceUsageReportModel
            {
                GroupId     = groupId,
                StartTime   = startTime,
                EndTime     = endTime,
                SessionCode = sessionCode
            });
            var response = await client.ExecuteAsync(request);

            if (response.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new Exception(response.Content.ToString());
            }
            else
            {
                sb.AppendLine(JToken.Parse(response.Content).ToString(Newtonsoft.Json.Formatting.Indented));
            }

            UserGroupResourceUsageReportExt userUsageReport = JsonConvert.DeserializeObject <UserGroupResourceUsageReportExt>(response.Content.ToString());

            return(userUsageReport);
        }
        public static UserGroupResourceUsageReportExt ConvertIntToExt(this UserGroupResourceUsageReport report)
        {
            UserGroupResourceUsageReportExt convert = new UserGroupResourceUsageReportExt()
            {
                UserReports = report.UserReport.Select(s => s.ConvertIntToExt())
                              .ToArray(),
                StartTime           = report.StartTime,
                EndTime             = report.EndTime,
                TotalCorehoursUsage = report.TotalUsage
            };

            return(convert);
        }