private PowerShellResults ExportObject(ExportUMCallDataRecordParameters parameters)
        {
            PSCommand psCommand = new PSCommand().AddCommand("Export-UMCallDataRecord");

            psCommand.AddParameters(parameters);
            return(base.Invoke(psCommand));
        }
        private string ConstructFilename(ExportUMCallDataRecordParameters parameters)
        {
            StringBuilder stringBuilder = new StringBuilder("UM_CDR");

            stringBuilder.Append("_");
            stringBuilder.Append(parameters.Date.ToString("yyyy-MM-dd"));
            stringBuilder.Append(".csv");
            return(stringBuilder.ToString());
        }
        public PowerShellResults ProcessRequest(HttpContext context)
        {
            ExDateTime date;

            if (!ExDateTime.TryParseExact(context.Request.QueryString["Date"], "d", Thread.CurrentThread.CurrentCulture, DateTimeStyles.None, out date))
            {
                throw new BadRequestException(new Exception("ExportUMCallHandler got a request with Date not specified in query param or Date is invalid."));
            }
            ExportUMCallDataRecordParameters exportUMCallDataRecordParameters = new ExportUMCallDataRecordParameters();

            exportUMCallDataRecordParameters.Date         = date;
            exportUMCallDataRecordParameters.UMDialPlan   = context.Request.QueryString["UMDialPlanID"];
            exportUMCallDataRecordParameters.UMIPGateway  = context.Request.QueryString["UMIPGatewayID"];
            exportUMCallDataRecordParameters.ClientStream = context.Response.OutputStream;
            context.Response.ContentType = "text/csv";
            context.Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", this.ConstructFilename(exportUMCallDataRecordParameters)));
            PowerShellResults powerShellResults = this.ExportObject(exportUMCallDataRecordParameters);

            if (this.IsValidUserError(powerShellResults))
            {
                powerShellResults = new PowerShellResults();
            }
            return(powerShellResults);
        }