This event is fired as a response to a custom sessions request either when the collection is resolved or when an error has occurred during the request processing.
Visual Basic |
---|
Public Event CustomSessionsResolved( _ ByVal cqg_sessions_collection As CQGSessionsCollection, _ ByVal cqg_error As CQGError _ ) |
- cqg_sessions_collection
Collection of resolved custom sessions.
If an error has occurred, the collection will be empty.
- cqg_error
CQGError object representing the error occurred during the custom sessions request.
If no error has occurred, the parameter value is either Nothing or invalid error object depending on the UsedFromATLClient setting of the configuration.
The parameter can be checked for validity via the CQGCEL.IsValid method.
For more information about custom sessions see this article in CQG Charting User Guide.
The examples below show how to request custom sessions via CQG API.
Option Explicit Private WithEvents CEL As CQGCEL Private Sub Form_Load() ' Initialize CQGCEL instance. On Error Goto errHndl Set CEL = New CQGCEL CEL.APIConfiguration.CollectionsThrowException = False ' Disable application readiness checking CEL.APIConfiguration.ReadyStatusCheck = rscOff CEL.Startup Exit Sub errHndl: MsgBox "Error occurred during CEL initialization. " & Err.Description End Sub Private Sub Form_Unload(Cancel As Integer) On Error Goto errHndl CEL.Shutdown Exit Sub errHndl: MsgBox "Error occurred during CEL initialization. " & Err.Description End Sub ' Event is fired when the CQGCEL object is successfully started up Private Sub CEL_CELStarted() Debug.Print "CEL Version : " & CEL.Environment.CELVersion End Sub ' Event is fired when error occures in CQGCEL execution Private Sub cel_DataError(ByVal obj As Object, ByVal errorDescription As String) ' Print the error description Debug.Print "Data Error : " & errorDescription End Sub ' Event is fired when some changes occurred in the connection ' with the CQG data server Private Sub CEL_DataConnectionStatusChanged(ByVal newStatus As CQG.eConnectionStatus) Dim status As String Select Case newStatus Case csConnectionDelayed status = "Delayed" Case csConnectionDown status = "Down" Case csConnectionUp status = "Up" End Select Debug.Print "Data Connection Status changed to " & status If newStatus = csConnectionUp Then RequestCustomSessions End If End Sub ' This function requests all available custom sessions Private Sub RequestCustomSessions() Debug.Print "Requesting custom sessions" CEL.RequestCustomSessions End Sub ' Event is fired when requested sessions collection is resolved ' or an error has occurred during the request processing Private Sub CEL_CustomSessionsResolved(ByVal sessionsCollection As CQG.ICQGSessionsCollection, ByVal cqgErr As CQG.ICQGError) Dim ss As CQGSessions Dim s As CQGSession Debug.Print "Custom sessions resolved" If Not cqgErr Is Nothing Then Debug.Print "Error occured during custom sessions request : " & cqgErr.Description Exit Sub End If ' Print requested sessions data For Each ss In sessionsCollection Debug.Print "Sessions name : " & ss.Name & ", type : " & ss.Type For Each s In ss Debug.Print vbTab & "Session name : " & s.Name Debug.Print vbTab & "Session time range : " & s.StartTime & " - " & s.EndTime Debug.Print vbTab & "Working days :" If ((s.WorkingWeekDays And eSessionWeekDays.swdSunday) = eSessionWeekDays.swdSunday) Then Debug.Print String(2, vbTab) & "Sunday" End If If ((s.WorkingWeekDays And eSessionWeekDays.swdMonday) = eSessionWeekDays.swdMonday) Then Debug.Print String(2, vbTab) & "Monday" End If If ((s.WorkingWeekDays And eSessionWeekDays.swdTuesday) = eSessionWeekDays.swdTuesday) Then Debug.Print String(2, vbTab) & "Tuesday" End If If ((s.WorkingWeekDays And eSessionWeekDays.swdWednesday) = eSessionWeekDays.swdWednesday) Then Debug.Print String(2, vbTab) & "Wednesday" End If If ((s.WorkingWeekDays And eSessionWeekDays.swdThursday) = eSessionWeekDays.swdThursday) Then Debug.Print String(2, vbTab) & "Thursday" End If If ((s.WorkingWeekDays And eSessionWeekDays.swdFriday) = eSessionWeekDays.swdFriday) Then Debug.Print String(2, vbTab) & "Friday" End If If ((s.WorkingWeekDays And eSessionWeekDays.swdSaturday) = eSessionWeekDays.swdSaturday) Then Debug.Print String(2, vbTab) & "Saturday" End If Next Next End Sub
using System; using System.Runtime.InteropServices; using CQG; namespace Samples { class CustomSessions : IDisposable { // CQGCEL instance declaration private CQGCEL cel = new CQGCELClass(); // Used to determine is the object manualy disposed private bool disposed = false; public CustomSessions() { // Initialize CQGCEL instance try { // Configure CEL cel.APIConfiguration.ReadyStatusCheck = eReadyStatusCheck.rscOff; cel.APIConfiguration.CollectionsThrowException = false; // Register to CEL's events cel.CELStarted += new _ICQGCELEvents_CELStartedEventHandler(cel_CELStarted); cel.DataError += new _ICQGCELEvents_DataErrorEventHandler(cel_DataError); cel.DataConnectionStatusChanged += new _ICQGCELEvents_DataConnectionStatusChangedEventHandler(cel_DataConnectionStatusChanged); cel.CustomSessionsResolved += new _ICQGCELEvents_CustomSessionsResolvedEventHandler(cel_CustomSessionsResolved); cel.Startup(); } catch (COMException ex) { Console.WriteLine( "Error occurred during CEL initialization. {0}", ex.Message ); } } ~CustomSessions() { Dispose(false); } #region CEL Event Handlers // Event is fired when the CQGCEL object is successfully started up void cel_CELStarted() { Console.WriteLine("CEL Version : {0}", cel.Environment.CELVersion); } // Event is fired when error occures in CQGCEL execution void cel_DataError(object obj, string errorDescription) { // Some error occurred Console.WriteLine("Data Error : " + errorDescription); } // Event is fired when some changes occurred in the connection // with the CQG data server void cel_DataConnectionStatusChanged(eConnectionStatus newStatus) { string status; switch (newStatus) { case eConnectionStatus.csConnectionDelayed: status = "Delayed"; break; case eConnectionStatus.csConnectionDown: status = "Down"; break; case eConnectionStatus.csConnectionUp: status = "Up"; break; default: status = "Unknown"; break; } Console.WriteLine("Data Connection Status changed to " + status); if (newStatus == eConnectionStatus.csConnectionUp) { RequestCustomSessions(); } } // This function requests all available custom sessions void RequestCustomSessions() { Console.WriteLine("Requesting custom sessions"); cel.RequestCustomSessions(); } // Event is fired when requested sessions collection is resolved // or an error has occurred during the request processing void cel_CustomSessionsResolved(CQGSessionsCollection sessionsCollection, CQGError err) { if (err != null) { Console.WriteLine("Error occured during custom sessions request : {0}", err.Description); return; } // Print requested sessions data foreach (CQGSessions ss in sessionsCollection) { Console.WriteLine("Sessions name : {0}, type : {1}", ss.Name, ss.Type); foreach (CQGSession s in ss) { Console.WriteLine("\t Session name : {0}", s.Name); Console.WriteLine("\t Session time range : {0} - {1}", s.StartTime, s.EndTime); Console.WriteLine("\t Working days :"); if ((s.WorkingWeekDays & eSessionWeekDays.swdSunday) == eSessionWeekDays.swdSunday) { Console.WriteLine("\t\t Sunday"); } if ((s.WorkingWeekDays & eSessionWeekDays.swdMonday) == eSessionWeekDays.swdMonday) { Console.WriteLine("\t\t Monday"); } if ((s.WorkingWeekDays & eSessionWeekDays.swdTuesday) == eSessionWeekDays.swdTuesday) { Console.WriteLine("\t\t Tuesday"); } if ((s.WorkingWeekDays & eSessionWeekDays.swdWednesday) == eSessionWeekDays.swdWednesday) { Console.WriteLine("\t\t Wednesday"); } if ((s.WorkingWeekDays & eSessionWeekDays.swdThursday) == eSessionWeekDays.swdThursday) { Console.WriteLine("\t\t Thursday"); } if ((s.WorkingWeekDays & eSessionWeekDays.swdFriday) == eSessionWeekDays.swdFriday) { Console.WriteLine("\t\t Friday"); } if ((s.WorkingWeekDays & eSessionWeekDays.swdSaturday) == eSessionWeekDays.swdSaturday) { Console.WriteLine("\t\t Saturday"); } } } } #endregion #region IDisposable Members public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion #region Private Methods private void Dispose(bool disposing) { // Check to see if Dispose has already been called if (!this.disposed) { // If disposing equals true, dispose all managed // and unmanaged resources if (disposing) { // Dispose managed resources } // If disposing is false, // only the following code is executed try { cel.Shutdown(); } catch { } } disposed = true; } #endregion } }