private void GetUsageDetails(CollectionUsageDetailsResult detailsUsage)
        {
            RemoteAppOperationStatusResult operationResult = null;

            // The request is async and we have to wait for the usage details to be produced here
            do
            {
                System.Threading.Thread.Sleep(5000);

                operationResult = CallClient(() => Client.OperationResults.Get(detailsUsage.UsageDetails.OperationTrackingId), Client.OperationResults);
            }
            while (operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Success &&
                operationResult.RemoteAppOperationResult.Status != RemoteAppOperationStatus.Failed);

            if (operationResult.RemoteAppOperationResult.Status == RemoteAppOperationStatus.Success)
            {
                WriteUsageDetails(detailsUsage);
            }
            else
            {
                ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                    Commands_RemoteApp.DetailedUsageFailureMessage,
                    String.Empty,
                    Client.Collections,
                    ErrorCategory.ResourceUnavailable);

                WriteError(error);
            }
        }
        private void WriteUsageDetails(CollectionUsageDetailsResult detailsUsage)
        {
            // 
            // Display the content pointed to by the returned URI
            //
            WebResponse response = null;

            WebRequest request = WebRequest.Create(detailsUsage.UsageDetails.SasUri);

            try
            {
                response = (HttpWebResponse)request.GetResponse();
                if (response == null)
                {
                    ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromString(
                                "Unable to retrieve Usage data", String.Empty, null, ErrorCategory.InvalidResult);
                    WriteError(error);
                    return;
                }
            }
            catch (Exception e)
            {
                ErrorRecord error = RemoteAppCollectionErrorState.CreateErrorRecordFromException(e, String.Empty, Client.Collections, ErrorCategory.InvalidResult);
                WriteError(error);
                return;
            }

            using (Stream dataStream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(dataStream))
                {
                    String csvContent = reader.ReadToEnd();
                    WriteObject(csvContent);
                }
            }
        }