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(); } }
/// <summary> /// Initiates the asset meta data. /// </summary> /// <param name="client">The client.</param> /// <param name="metadataFormat">The metadata format.</param> /// <param name="initiationMode">The initiation mode.</param> /// <param name="onsuccessclose">if set to <c>true</c> [onsuccessclose].</param> /// <returns></returns> /// <exception cref="AIPOC.Exceptions.OlsaSecurityException"></exception> public static string AI_InitiateAssetMetaData(OlsaPortTypeClient client, assetMetadataFormat metadataFormat, assetInitiationMode initiationMode, bool onsuccessclose = false) { HandleResponse handleResponse = new HandleResponse(); try { log.InfoFormat("Sending AI_InitiateAssetMetadata Request. Format: {0} Mode: {1}", metadataFormat, initiationMode); InitiateAssetMetaDataRequest request = new InitiateAssetMetaDataRequest(); //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.initiationMode = initiationMode; request.metadataFormat = metadataFormat; handleResponse = client.AI_InitiateAssetMetaData(request); } catch (WebException) { // This captures any Web Exepctions such as DNS lookup errors, HTTP status errors such as 404, 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; } //Olsa.GeneralFault exception will be thrown for issues like parameters invalid, user does could not be created etc catch (FaultException <Olsa.GeneralFault> ) { 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 //Check the values in the web.config are correct for OLSA.CustomerID and OLSA.SharedSecret - these are case sensitive //Check the time on the machine, the SOAP message is valid for 5 minutes. This means that if the time on the calling machine //is to slow OR to fast then the SOAP message will be invalid. throw new Exceptions.OlsaSecurityException(); } throw; } catch (CommunicationException) { throw; } catch (Exception) { //Any other type of exception, perhaps out of memory throw; } finally { if (client != null) { if (client.State == CommunicationState.Faulted) { client.Abort(); } if (onsuccessclose) { client.Close(); } } } return(handleResponse.handle); }
/// <summary> /// Pollfors the report. /// </summary> /// <param name="reportId">The report identifier.</param> /// <param name="client">The client.</param> /// <param name="closeclient">if set to <c>true</c> [closeclient].</param> /// <returns></returns> public static UrlResponse PollforReport(string reportId, OlsaPortTypeClient client, bool closeclient = false) { //Set up our response object UrlResponse response = null; try { //Create our request PollForReportRequest request = new PollForReportRequest(); //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.reportId = reportId; response = client.UTIL_PollForReport(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); }