예제 #1
0
        /// <summary>
        /// Queries the Graph API and returns the emitted string output
        /// </summary>
        /// <param name="ReportType"></param>
        /// <param name="reportPeriod"></param>
        /// <param name="reportDate"></param>
        /// <param name="defaultRecordBatch">(OPTIONAL) will default to 500</param>
        /// <param name="betaEndPoint">(OPTIONAL) will default to false</param>
        /// <returns></returns>
        public string ProcessReport(ReportUsageTypeEnum ReportType, ReportUsagePeriodEnum reportPeriod, Nullable <DateTime> reportDate, int defaultRecordBatch = 500, bool betaEndPoint = false)
        {
            var serviceQuery = new QueryFilter(defaultRecordBatch, betaEndPoint)
            {
                O365ReportType = ReportType,
                O365Period     = reportPeriod,
                Date           = reportDate
            };

            var response = ResponseReader.RetrieveData(serviceQuery);

            return(response);
        }
        /// <summary>
        /// #Build the request URL and invoke
        ///     Sample: OneDriveActivity(view='Detail',period='D7')/content
        /// </summary>
        /// <param name="graphUrl">Represents the Graph URL for Usage Reporting which should have two parameters {0}{1}</param>
        /// <returns></returns>
        internal Uri ToUrl(string graphUrl)
        {
            var parameterset = string.Empty;

            // If period is specified then add that to the parameters except when not is supported
            var doesNotSupportPeriod = new ReportUsageTypeEnum[]
            {
                ReportUsageTypeEnum.getOffice365ActivationsUserDetail,
                ReportUsageTypeEnum.getOffice365ActivationCounts,
                ReportUsageTypeEnum.getOffice365ActivationsUserCounts
            };

            if (O365Period.HasValue && !doesNotSupportPeriod.Any(a => a == O365ReportType))
            {
                parameterset = string.Format("period='{0}'", O365Period.Value.ToString("f"));
            }

            // If the date is specified then add that to the parameters if it is supported
            var doesSupportDate = new ReportUsageTypeEnum[]
            {
                ReportUsageTypeEnum.getOffice365ActiveUserDetail,
                ReportUsageTypeEnum.getOffice365GroupsActivityDetail,
                ReportUsageTypeEnum.getOneDriveActivityUserDetail,
                ReportUsageTypeEnum.getOneDriveUsageAccountDetail,
                ReportUsageTypeEnum.getSharePointActivityUserDetail,
                ReportUsageTypeEnum.getSharePointSiteUsageDetail,
                ReportUsageTypeEnum.getSkypeForBusinessActivityUserDetail,
                ReportUsageTypeEnum.getSkypeForBusinessDeviceUsageUserDetail
            };

            if (Date.HasValue && doesSupportDate.Any(a => a == O365ReportType))
            {
                parameterset = string.Format("date={0}", Date.Value.ToString("yyyy-MM-dd"));
            }


            if (FormattedOutput == ReportUsageFormatEnum.JSON)
            {
                var supportsTop = new ReportUsageTypeEnum[]
                {
                    ReportUsageTypeEnum.getOffice365ActiveUserDetail,
                    ReportUsageTypeEnum.getOffice365GroupsActivityDetail,
                    ReportUsageTypeEnum.getOneDriveActivityUserDetail,
                    ReportUsageTypeEnum.getOneDriveUsageAccountDetail,
                    ReportUsageTypeEnum.getSharePointSiteUsageDetail,
                    ReportUsageTypeEnum.getSkypeForBusinessActivityUserDetail,
                    ReportUsageTypeEnum.getSkypeForBusinessDeviceUsageUserDetail
                };
                var topIsDirty = false;
                if (supportsTop.Any(a => a == O365ReportType))
                {
                    topIsDirty = true;
                    graphUrl  += "?$top=" + RecordBatchCount;
                }
                graphUrl += (topIsDirty ? "&" : "?") + "$format=application/json";
            }


            // JSON Format not supported by V1.0 endpoint
            var versionuri = (BetaEndPoint || (FormattedOutput == ReportUsageFormatEnum.JSON) ? "beta" : "v1.0");

            // If parameter is specified enable parenthesis
            if (!string.IsNullOrEmpty(parameterset))
            {
                parameterset = $"({parameterset})";
            }

            var uri = new Uri(string.Format(graphUrl, versionuri, O365ReportType, parameterset));

            return(uri);
        }