Exemple #1
0
        /// <summary>
        /// Initiates the full course listing.
        /// </summary>
        /// <param name="scopingUser">The username for scoping the report if report uses it</param>
        /// <param name="format">The format</param>
        /// <param name="report">The report name</param>
        /// <param name="reportParams">The report parameters.</param>
        /// <param name="language">The language, or NULL</param>
        /// <param name="duration">The duration to retain report (Use one of the following numeric values: 1 - 1 hour, 2 - 8 hours, 3 - 24 hours.</param>
        /// <param name="client">The client.</param>
        /// <param name="closeclient">if set to <c>true</c> [closeclient].</param>
        /// <returns></returns>
        public static HandleResponse SubmitReport(string scopingUser, reportFormat format, string report, MapItem[] reportParams, string language, int duration, OlsaPortTypeClient client, bool closeclient = false)
        {
            //Set up our response object
            HandleResponse response = null;

            try
            {
                //Create our request
                SubmitReportRequest request = new SubmitReportRequest();

                //Pull the OlsaAuthenticationBehviour so we can extract the customerid
                AuthenticationBehavior olsaCredentials = (AuthenticationBehavior)client.ChannelFactory.Endpoint.Behaviors.Where(p => p.GetType() == typeof(AuthenticationBehavior)).FirstOrDefault();
                request.customerId = olsaCredentials.UserName;

                request.scopingUserId    = scopingUser;
                request.reportFormat     = format;
                request.report           = report;
                request.language         = language;
                request.duration         = duration;
                request.reportParameters = reportParams;


                response = client.UD_SubmitReport(request);
            }
            catch (WebException)
            {
                // This captures any Web Exceptions such as proxy errors etc
                // See http://msdn.microsoft.com/en-us/library/48ww3ee9(VS.80).aspx
                throw;
            }
            catch (TimeoutException)
            {
                //This captures the WCF timeout exception
                throw;
            }
            //WCF fault exception will be thrown for any other issues such as Security
            catch (FaultException fe)
            {
                if (fe.Message.ToLower(CultureInfo.InvariantCulture).Contains("the security token could not be authenticated or authorized"))
                {
                    //The OLSA Credentials specified could not be authenticated
                    throw;
                }
                throw;
            }
            catch (Exception)
            {
                //Any other type of exception, perhaps out of memory
                throw;
            }
            finally
            {
                //Shutdown and dispose of the client
                if (client != null)
                {
                    if (client.State == CommunicationState.Faulted)
                    {
                        client.Abort();
                    }
                    if (closeclient)
                    {
                        //We cannot resue client if we close
                        client.Close();
                    }
                }
            }
            return(response);
        }
Exemple #2
0
        static void Process(Uri endpoint, string customerId, string sharedSecret)
        {
            //Create the OLSA Web Services Client using code
            OlsaPortTypeClient client = Helpers.Olsa.GetOLSAClient(endpoint, customerId, sharedSecret);

            Console.WriteLine("Issuing the UD_SubmitReport Request");
            Console.WriteLine("------------------------------------");
            HandleResponse handleResponse = new HandleResponse();

            //--------------------------------------------------------------------------------------------
            //Define report settings here to ease changes
            string       scopingUserId  = "admin";
            reportFormat reportFormat   = reportFormat.CSV;
            string       reportFilename = "report." + reportFormat.ToString();

            string reportLanguage     = "en_US"; //en_US only supported value
            int    reportRetainperiod = 3;       //1 - 1 hour, 2 - 8 hours, 3 - 24 hours.

            //For details of report names and parameters see https://documentation.skillsoft.com/en_us/skillport/8_0/ah/35465.htm
            string reportName = "summary_catalog";
            //Define report parameters
            List <MapItem> paramList = new List <MapItem>();

            paramList.Add(new MapItem()
            {
                key = "asset_category", value = "1,2,3,4,5,21"
            });
            paramList.Add(new MapItem()
            {
                key = "display_options", value = "all"
            });


            //--------------------------------------------------------------------------------------------

            //Submit Report request
            try
            {
                handleResponse = Helpers.Olsa.SubmitReport(scopingUserId, reportFormat, reportName, paramList.ToArray(), reportLanguage, reportRetainperiod, client, false);

                //Minutes between polls
                int sleepInterval = 2;
                Console.WriteLine("Handle: {0}", handleResponse.handle);

                UrlResponse url = null;

                for (int i = 0; i < 10; i++)
                {
                    Console.WriteLine("{0}: Sleeping {1} minutes", DateTime.UtcNow.ToLongTimeString(), sleepInterval);
                    //ms - so here we sleep for 10 minutes
                    System.Threading.Thread.Sleep(sleepInterval * 60 * 1000);

                    try
                    {
                        url = Helpers.Olsa.PollforReport(handleResponse.handle, client, false);
                        break;
                    }
                    catch (FaultException <Olsa.DataNotReadyYetFault> )
                    {
                        //The report has not completed generation, we are checking for a Specific OLSA Exception
                        Console.WriteLine("{0}: The specified report is not yet ready", DateTime.UtcNow.ToLongTimeString());
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("{0}: Issue while Polling for Report.", DateTime.UtcNow.ToLongTimeString());
                        Console.WriteLine("{0}: Exception: {1}", DateTime.UtcNow.ToLongTimeString(), ex.ToString());
                        throw;
                    }
                }

                if (url != null)
                {
                    WebClient myWebClient = new WebClient();
                    Console.WriteLine("{0}: Downloading Report: {1}", DateTime.UtcNow.ToLongTimeString(), url.olsaURL);
                    myWebClient.DownloadFile(url.olsaURL, reportFilename);
                    Console.WriteLine("{0}: Successfully Downloaded: {1}", DateTime.UtcNow.ToLongTimeString(), reportFilename);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("{0}: Issue while Submitting Report.", DateTime.UtcNow.ToLongTimeString());
                Console.WriteLine("{0}: Exception: {1}", DateTime.UtcNow.ToLongTimeString(), ex.ToString());
            }
            //Now we can close the client
            if (client != null)
            {
                if (client.State == CommunicationState.Faulted)
                {
                    client.Abort();
                }

                client.Close();
            }
        }
Exemple #3
0
        private Exception RunSSRSReport(ReportParameters Report, ActivityRun activityRun, reportFormat format)
        {
            rsExec     = new ReportExecutionService();
            rsExec.Url = Properties.Settings.Default.RE2005_ReportExecutionService;

            rsExec.UseDefaultCredentials = true;

            string historyID  = null;
            string deviceInfo = null;

            Byte[] results;
            string encoding  = String.Empty;
            string mimeType  = String.Empty;
            string extension = String.Empty;

            Warning[] warnings  = null;
            string[]  streamIDs = null;

            var p = "";

            for (int i = 0; i < Report.Parameters.Count; i++)
            {
                p = "Param[" + i.ToString() + "]" + Report.Parameters[i].Name + "|" + Report.Parameters[i].Value.ToString() + Environment.NewLine + p;
            }

            // Path of the Report - XLS, PDF etc.
            Report.OutputFilePath = GetOutputFileName(Report);
            string FilePath = outputFolder + Report.OutputFilePath + "." + format.ToString().ToLower();

            // Name of the report - Please note this is not the RDL file.
            string _reportName = @"/GenevaReports/" + Report.Name;

            try
            {
                ExecutionInfo    ei         = rsExec.LoadReport(_reportName, historyID);
                ParameterValue[] parameters = new ParameterValue[Report.Parameters.Count];

                for (int i = 0; i < Report.Parameters.Count; i++)
                {
                    parameters[i]       = new ParameterValue();
                    parameters[i].Name  = Report.Parameters[i].Name;
                    parameters[i].Value = (string)Report.Parameters[i].Value;
                }

                rsExec.SetExecutionParameters(parameters, "en-IE");

                DataSourceCredentials dataSourceCredentials2 = new DataSourceCredentials();
                dataSourceCredentials2.DataSourceName = Properties.Settings.Default.DataSourceName;
                dataSourceCredentials2.UserName       = Properties.Settings.Default.GenevaUser;
                dataSourceCredentials2.Password       = Properties.Settings.Default.GenevaPass;


                DataSourceCredentials[] _credentials2 = new DataSourceCredentials[] { dataSourceCredentials2 };

                var c = "";
                for (int i = 0; i < _credentials2.Length; i++)
                {
                    c = "_credentials2[" + i.ToString() + "]:" + _credentials2[i].DataSourceName + "|" +
                        _credentials2[i].UserName + "|" +
                        _credentials2[i].Password + "|" + Environment.NewLine + c;
                }

                rsExec.SetExecutionCredentials(_credentials2);
                //rsExec.UseDefaultCredentials = true;

                results = rsExec.Render(format.ToString(), deviceInfo, out extension,
                                        out encoding,
                                        out mimeType,
                                        out warnings,
                                        out streamIDs);

                using (FileStream stream = File.OpenWrite(FilePath))
                {
                    stream.Write(results, 0, results.Length);
                }
            }
            catch (Exception ex)
            {
                status = "--- ERROR ---" + Environment.NewLine +
                         "Running PDF Report: " + Report.Name + Environment.NewLine +
                         ex.Message + Environment.NewLine +
                         "--------------" + Environment.NewLine +
                         status + Environment.NewLine;
                return(new Exception(status));
            }

            return(null);
        }