Appointments Stress Test Example for WPF

Nevron NOV Schedule for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF Schedule examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Appointments Stress Test Example for WPF Description

This example demonstrates how NOV Schedule handles 100,000 appointments with different categories (colors).


Appointments Stress Test Example

C# Appointments Stress Test Example Code for Nevron Schedule for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Dom;
using Nevron.Nov.Globalization;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Schedule;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NAppointmentsStressTestExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

		#region Example

		public NWidget CreateExampleContent()
		{
			// Create a simple schedule
			NScheduleViewWithRibbon scheduleViewWithRibbon = new NScheduleViewWithRibbon();
			m_ScheduleView = scheduleViewWithRibbon.View;

			m_ScheduleView.Document.PauseHistoryService();
			try
			{
				InitSchedule(m_ScheduleView.Content);
			}
			finally
			{
				m_ScheduleView.Document.ResumeHistoryService();
			}

			// Return the commanding widget
			return scheduleViewWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			return null;
		}
		public string GetExampleDescription()
		{
			return String.Format(NCultureInfo.EnglishUS, @"

This example demonstrates how NOV Schedule handles {0:N0} appointments with different categories (colors).

", TotalAppointments); } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Schedule Appointments", "https://www.nevron.com/docs/openvision/schedule-appointments.html"), ("Schedule View", "https://www.nevron.com/docs/openvision/schedule-view.html"), }; } #endregion #region Implementation private void InitSchedule(NSchedule schedule) { m_Random = new Random(); int totalDays = TotalAppointments / AppointmentsPerDay; DateTime date = DateTime.Today.AddDays(-totalDays / 2); // Generate the random appointments NAppointmentCollection appointments = schedule.Appointments; for (int i = 0; i < totalDays; i++) { AddRandomAppointments(appointments, date); date = date.AddDays(1); } // Switch the schedule to week view schedule.ViewMode = ENScheduleViewMode.Week; } /// /// Adds some random appointments for the given date. /// /// /// private void AddRandomAppointments(NAppointmentCollection appointments, DateTime date) { int lastRnd = -1; for (int i = 0; i < AppointmentsPerDay; i++) { // Generate random subject int rnd; do { rnd = m_Random.Next(0, AppointmentSubjects.Length); } while (rnd == lastRnd); string subject = AppointmentSubjects[rnd]; // Generate random start hour from 0 to 24 double startHour = m_Random.NextDouble() * 24; // Generate random duration from 0.5 to 2.5 hours double duration = 0.5 + m_Random.NextDouble() * 2; // Create and add the appointment NAppointment appointment = new NAppointment(subject, date.AddHours(startHour), date.AddHours(startHour + duration)); appointment.Category = CategoryColors[rnd / 2]; appointments.Add(appointment); lastRnd = rnd; } } #endregion #region Event Handlers #endregion #region Fields private NScheduleView m_ScheduleView; private Random m_Random; #endregion #region Static Methods #endregion #region Constants private const int AppointmentsPerDay = 20; private const int TotalAppointments = 100000; private static readonly string[] AppointmentSubjects = new string[] { "Travel to Work", "Travel back home", "Conference", "Lunch", "Meeting with Fiends", "Reading the News", "Video Presentation", "Web Meeting", "Gym Workout", "Jogging", "Family Dinner", "House Cleaning" }; private static readonly string[] CategoryColors = new string[] { NCategory.Color.Orange, NCategory.Color.Red, NCategory.Color.Blue, NCategory.Color.Green, NCategory.Color.Purple, NCategory.Color.Yellow, }; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Appointments Stress Test Example for WPF Solution

VB.NET Appointments Stress Test Example Code for Nevron Schedule for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Globalization
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Schedule
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NAppointmentsStressTestExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
		pairBox.FillMode = ENStackFillMode.First
		pairBox.FitMode = ENStackFitMode.First
		pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

		' Host the example in the form
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            ' Create a simple schedule
            Dim scheduleViewWithRibbon As NScheduleViewWithRibbon = New NScheduleViewWithRibbon()
            m_ScheduleView = scheduleViewWithRibbon.View

            m_ScheduleView.Document.PauseHistoryService()
            Try
                InitSchedule(m_ScheduleView.Content)
            Finally
                m_ScheduleView.Document.ResumeHistoryService()
            End Try

            ' Return the commanding widget
            Return scheduleViewWithRibbon
        End Function
        Public Function CreateExampleControls() As NWidget
            Return Nothing
        End Function
        Public Function GetExampleDescription() As String
            Return String.Format(NCultureInfo.EnglishUS, "

This example demonstrates how NOV Schedule handles {0:N0} appointments with different categories (colors).

", TotalAppointments) End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Schedule Appointments", "https://www.nevron.com/docs/openvision/schedule-appointments.html"), ("Schedule View", "https://www.nevron.com/docs/openvision/schedule-view.html")} End Function #End Region #Region "Implementation" Private Sub InitSchedule(schedule As NSchedule) m_Random = New Random() Dim totalDays As Integer = TotalAppointments / AppointmentsPerDay Dim [date] = Date.Today.AddDays(-totalDays / 2) ' Generate the random appointments Dim appointments = schedule.Appointments For i = 0 To totalDays - 1 AddRandomAppointments(appointments, [date]) [date] = [date].AddDays(1) Next ' Switch the schedule to week view schedule.ViewMode = ENScheduleViewMode.Week End Sub ''' ''' Adds some random appointments for the given date. ''' ''' ''' Private Sub AddRandomAppointments(appointments As NAppointmentCollection, [date] As Date) Dim lastRnd = -1 For i = 0 To AppointmentsPerDay - 1 ' Generate random subject Dim rnd As Integer Do rnd = m_Random.Next(0, AppointmentSubjects.Length) Loop While rnd = lastRnd Dim subject = AppointmentSubjects(rnd) ' Generate random start hour from 0 to 24 Dim startHour As Double = m_Random.NextDouble() * 24 ' Generate random duration from 0.5 to 2.5 hours Dim duration As Double = 0.5 + m_Random.NextDouble() * 2 ' Create and add the appointment Dim appointment As NAppointment = New NAppointment(subject, [date].AddHours(startHour), [date].AddHours(startHour + duration)) appointment.Category = CategoryColors(rnd / 2) appointments.Add(appointment) lastRnd = rnd Next End Sub #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_ScheduleView As NScheduleView Private m_Random As Random #End Region #Region "Static Methods" #End Region #Region "Constants" Private Const AppointmentsPerDay As Integer = 20 Private Const TotalAppointments As Integer = 100000 Private Shared ReadOnly AppointmentSubjects As String() = New String() {"Travel to Work", "Travel back home", "Conference", "Lunch", "Meeting with Fiends", "Reading the News", "Video Presentation", "Web Meeting", "Gym Workout", "Jogging", "Family Dinner", "House Cleaning"} Private Shared ReadOnly CategoryColors As String() = New String() {NCategory.Color.Orange, NCategory.Color.Red, NCategory.Color.Blue, NCategory.Color.Green, NCategory.Color.Purple, NCategory.Color.Yellow} #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Appointments Stress Test Example for WPF Solution

Related Documentation Links