/// <summary>
        /// An example demonstrating how to find particular session in the Database based on session detail/item.
        /// </summary>
        /// <returns>String value, an output of the example run</returns>
        public string FindSessionsByItems()
        {
            try
            {
                // Create a session and add data first
                var sessionCreation = new SessionCreationExample(this.connectionString);
                sessionCreation.CreateSessionAndAddData();
                var clientSession = this.sessionManager.CreateSession(this.connectionString, SessionKey.NewKey(), "NewSession", DateTime.Now, "TAG-310");
                var session       = clientSession.Session;

                session.Items.Add(new SessionDataItem("Driver Name", "xxxxxxxxxx"));
                session.Items.Add(new SessionDataItem("Driver Height", 170.6));
                clientSession.Close();
                MainForm mainForm = MainForm.Main();

                // Search for only sessions with particular session items
                var items = new List <SessionDataItem>
                {
                    new SessionDataItem("Driver Name", "xxxxxxxxxx"),
                    new SessionDataItem("Driver Height", 170.6)
                };
                IList <SessionSummary> sessions = this.sessionManager.FindBySessionItems(items, this.connectionString);
                if (sessions.Count > 0)
                {
                    mainForm.dataGrid.Columns.Add("guidp", "Session GUID");
                    mainForm.dataGrid.Columns.Add("SessionItem1", "SessionItem1");
                    mainForm.dataGrid.Columns.Add("SessionItem2", "SessionItem2");
                    mainForm.dataGrid.Columns.Add("startTime", "Start timestamp");
                    mainForm.dataGrid.Columns.Add("endTime", "End timestamp");
                    mainForm.dataGrid.Columns.Add("laps", "Laps");
                    mainForm.dataGrid.Columns.Add("dateOfRecording", "Date of recording");
                    foreach (SessionSummary sessionSummary in sessions)
                    {
                        // Session summary object has properties such as Items, Start/End time, Laps etc.
                        mainForm.dataGrid.Rows.Add(new object[]
                        {
                            sessionSummary.Key,
                            string.Format("{0} = {1}", sessionSummary.Items[0].Name, sessionSummary.Items[0].Value),
                            string.Format("{0} = {1}", sessionSummary.Items[1].Name, sessionSummary.Items[1].Value),
                            sessionSummary.StartTime,
                            sessionSummary.EndTime,
                            sessionSummary.Laps.Count,
                            sessionSummary.TimeOfRecording,
                        });
                    }
                }

                return(string.Format("The given Session details found {0} sessions in the Database", sessions.Count));
            }
            catch (Exception)
            {
                return(null);
            }
        }
        /// <summary>
        /// Method for clicking the CreateSession button
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private void OnCreateSessionClick(object sender, EventArgs e)
        {
            this.resultMessage.Text = " ";
            this.dataGrid.Rows.Clear();
            this.display.Series[0].Points.Clear();
            this.DisableAllButtons();

            // Call the Create Session example method to create session and add data
            var sessionCreationExample = new SessionCreationExample(this.connectionStringTextBox.Text);
            var key = sessionCreationExample.CreateSessionAndAddData();

            this.resultMessage.Text = key != SessionKey.Empty ?
                                      string.Format("\nSession with the Key {0} created successfully.", key)
                                        : "\nError creating the session";

            this.EnableAllButtons();
        }
Esempio n. 3
0
        /// <summary>
        /// An example demonstrating how to find all the sessions in a SQL race database.
        /// </summary>
        /// <returns>String value, an output of the example run</returns>
        public string FindAllSessionsInDataBase()
        {
            try
            {
                // Create a session and add data first
                var sessionCreation = new SessionCreationExample(this.connectionString);
                sessionCreation.CreateSessionAndAddData();
                MainForm mainForm = MainForm.Main();

                // Search for all sessions in the database
                IList <SessionSummary> sessions = this.sessionManager.FindBySessionItems(null, this.connectionString);
                if (sessions.Count > 0)
                {
                    mainForm.dataGrid.Columns.Add("guidp", "Session GUID");
                    mainForm.dataGrid.Columns.Add("startTime", "Start timestamp");
                    mainForm.dataGrid.Columns.Add("endTime", "End timestamp");
                    mainForm.dataGrid.Columns.Add("laps", "Laps");
                    mainForm.dataGrid.Columns.Add("dateOfRecording", "Date of recording");

                    foreach (SessionSummary sessionSummary in sessions)
                    {
                        mainForm.dataGrid.Rows.Add(new object[]
                        {
                            sessionSummary.Key,
                            sessionSummary.StartTime,
                            sessionSummary.EndTime,
                            sessionSummary.Laps.Count,
                            sessionSummary.TimeOfRecording
                        });
                    }
                }

                return(string.Format("The given connection string found {0} sessions in the Database", sessions.Count));
            }
            catch (Exception)
            {
                return(null);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// An example demonstrating how to load a session and read data
        /// </summary>
        /// <returns>String value, an output of the example run</returns>
        public string LoadSessionAndReadData()
        {
            try
            {
                const string Parameter       = "highFrequency_1KHz";
                const int    NumberOfSamples = 25;

                // Create the session and add data first
                var        sessionCreation = new SessionCreationExample(this.connectionString);
                SessionKey sessionKey      = sessionCreation.CreateSessionAndAddData();

                // Load the just created session
                var clientSession = this.sessionManager.Load(sessionKey, this.connectionString);

                var session = clientSession.Session;
                // Read parameters
                var parameters = new List <ParameterBase>(session.Parameters);

                // Read all channels
                var channels = parameters.OfType <Parameter>().SelectMany(p => p.Channels);

                // Read all conversions
                var conversions = new List <ConversionBase>(session.Conversions);

                // Read Session details and constants
                var sessionDataItems = new List <SessionDataItem>(session.Items);
                var constants        = new List <Constant>(session.Constants);

                // Read all the Laps, Lap data items and lap constants
                var laps         = new List <Lap>(session.LapCollection);
                var lapDataItems = new List <LapDataItem>(session.LapCollection.LapItems);
                var lapConstants = new List <LapConstant>(session.LapCollection.Constants);

                // Use PDA to read the data

                this.data       = new double[NumberOfSamples];
                this.timeStamps = new long[NumberOfSamples];
                this.dataStatus = new DataStatusType[NumberOfSamples];

                var pdaParameter = parameters.FirstOrDefault(p => p.Identifier == Parameter) as Parameter;
                if (pdaParameter != null)
                {
                    var pda = session.CreateParameterDataAccess(pdaParameter.Identifier);
                    pda.GoTo(session.StartTime);

                    // GetNextData returns samples values
                    pda.SampleTime = pdaParameter.Channels[0].Interval;
                    pda.GetNextData(NumberOfSamples, template: new ParameterValuesTemplate {
                        Data = data, DataStatus = this.dataStatus
                    });

                    // GetNextSamples returns actual samples
                    pda.GetNextSamples(NumberOfSamples, template: new ParameterValuesTemplate
                    {
                        Data       = this.data,
                        DataStatus = this.dataStatus,
                        Timestamp  = this.timeStamps
                    });
                }

                clientSession.Close();

                return
                    (new StringBuilder().AppendFormat("{1}Session with the Key {0} loaded successfully.{1}", sessionKey, Environment.NewLine)
                     .AppendFormat("Parameters = {0}{1}", parameters.Count, Environment.NewLine)
                     .AppendFormat("Channels = {0}{1}", channels.Count(), Environment.NewLine)
                     .AppendFormat("Conversions = {0}{1}", conversions.Count, Environment.NewLine)
                     .AppendFormat("SessionDataItems = {0}{1}", sessionDataItems.Count, Environment.NewLine)
                     .AppendFormat("Constants = {0}{1}", constants.Count, Environment.NewLine)
                     .AppendFormat("Laps = {0}{1}", laps.Count, Environment.NewLine)
                     .AppendFormat("LapConstants = {0}{1}", lapConstants.Count, Environment.NewLine)
                     .AppendFormat("LapDataItems = {0}", lapDataItems.Count)
                     .ToString());
            }
            catch (Exception)
            {
                return(null);
            }
        }