public UsageManagementWrapper(string username, string password) { this.usageManager = new UsageReportingClient(); // Ensure server certificate is validated CertificateValidation.EnsureCertificateValidation(); this.authentication = new PanoptoScheduleUploader.Services.UsageManagement.AuthenticationInfo() { UserKey = username, Password = password }; }
/// <summary> /// Get stats for designated session /// </summary> /// <param name="serverName">Server name</param> /// <param name="authUserKey">User name</param> /// <param name="authPassword">Password</param> /// <param name="sessionID">Session ID</param> /// <param name="sessionName">Session name</param> /// <param name="folderName">Folder name</param> /// <param name="sessionLength">Session length</param> /// <returns>String containing stats for given session</returns> public static string GetAllStatsForSession(string serverName, string authUserKey, string authPassword, Guid sessionID, string sessionName, string folderName, double?sessionLength) { string sessionStats = String.Empty; List <DetailedUsageResponseItem> allResponsesForSession = new List <DetailedUsageResponseItem>(); // Get detailed stats // Permissions for user management UsageReporting.AuthenticationInfo usageAuth = new UsageReporting.AuthenticationInfo() { UserKey = authUserKey, Password = authPassword }; // Sanitize the session name for a CSV if (sessionName.Contains(",")) { sessionName = sessionName.Replace(",", ""); } if (folderName.Contains(",")) { folderName = folderName.Replace(",", ""); } UsageReportingClient urc = new UsageReportingClient( new BasicHttpsBinding(), new EndpointAddress(string.Format(UsageReportingEndpointFormat, serverName))); UsageReporting.Pagination pagination = new UsageReporting.Pagination(); pagination.MaxNumberResults = MaxPerPage; pagination.PageNumber = 0; try { // Get all detailed usage and store in allResponsesForSession DetailedUsageResponse usageResponse = urc.GetSessionDetailedUsage( usageAuth, sessionID, pagination, BeginDate, EndDate); if (usageResponse != null && usageResponse.TotalNumberResponses > 0) { foreach (DetailedUsageResponseItem responseItem in usageResponse.PagedResponses) { allResponsesForSession.Add(responseItem); } if (usageResponse.TotalNumberResponses > usageResponse.PagedResponses.Length) { int totalPages = usageResponse.TotalNumberResponses / MaxPerPage; // Get more data for (int page = 1; page < totalPages; page++) { pagination.PageNumber = page; usageResponse = urc.GetSessionDetailedUsage( usageAuth, sessionID, pagination, BeginDate, EndDate); foreach (DetailedUsageResponseItem responseItem in usageResponse.PagedResponses) { allResponsesForSession.Add(responseItem); } } } // If we have any stats, collate them by user if (allResponsesForSession.Count > 0) { Dictionary <Guid, DateTime> userViewDates; Dictionary <Guid, bool[]> userStatsCollection = CollateStatsByUser(allResponsesForSession, sessionLength, out userViewDates); foreach (KeyValuePair <Guid, bool[]> userStat in userStatsCollection) { sessionStats += PrintStatsData( serverName, authUserKey, authPassword, userStat, sessionID, sessionName, folderName, userViewDates[userStat.Key]); } } } else { string noneFormat = "{0}, {1}, none,,, {2}\n"; sessionStats = String.Format(noneFormat, sessionID.ToString(), sessionName, folderName); } } catch (Exception) { } return(sessionStats); }