Click here to Skip to main content
15,886,199 members
Articles / Programming Languages / C#

UniversalSerializer

Rate me:
Please Sign up or sign in to vote.
4.97/5 (108 votes)
15 Apr 2018Ms-RL31 min read 258K   4K   299  
An universal and easy serialization library for .NET and .NET Core.

// Copyright Christophe Bertrand.

//#define TIMER_DEBUGGING

using System;
using System.Collections;
using System.Windows;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Linq;
using System.Windows.Media;
using System.IO;

namespace UniversalSerializerResourceTests
{

	public enum StreamManagement { SerializeInRAM, SerializeToFile };

	/// <summary>
	/// Logique d'interaction pour MainWindow.xaml
	/// </summary>
	public partial class MainWindow : Window
	{

		public IEnumerable SerializersCollection { get {
			return
				CommonOptions.SerializerInstances.Select((ser) => ser.Name);
		} }

		public IEnumerable DataCollection
		{			get
			{				return AvailableDataDescriptors.Descriptors;			}		}

		public IEnumerable StreamManagementCollection
		{
			get
			{
				return Enum.GetValues(typeof(StreamManagement));
			}
		}

		ObservableCollection<string> LogStrings { get; set; }
		ObservableCollection<string> SeriesLogStrings { get; set; }

		readonly Brush NormalTextboxBackgroundColor;
		readonly Brush OrangeBrush = new SolidColorBrush(new Color() { R = 255, G = 160, B = 80, A = 255 });

		public MainWindow()
		{
			InitializeComponent();

			this.NormalTextboxBackgroundColor = this.TableFileName.Background;
			this.TableFileName.TextChanged += TableFileName_TextChanged;

			this.LogStrings = new ObservableCollection<string>();
			this.Log.ItemsSource = this.LogStrings;

			this.SeriesLogStrings = new ObservableCollection<string>();
			this.SeriesLog.ItemsSource = this.SeriesLogStrings;

			TableFileName_TextChanged(null, null);
		}

		void TableFileName_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
		{
			bool PathExists;
			try
			{
				PathExists = Directory.Exists(Path.GetDirectoryName(TableFileName.Text));
			}
			catch
			{
				PathExists = false;
			}

			this.TableFileName.Background =
				PathExists ?
				this.NormalTextboxBackgroundColor
				: OrangeBrush;
		}

		private void Button_Click(object sender, RoutedEventArgs e)
		{
			this.UnitTestOptions.Compute(CommonOptions.SerializerInstances[this.Serializer.SelectedIndex], null,null);
		}


		private void Window_Closed(object sender, EventArgs e)
		{
			//Application.Current.Shutdown(); // closes any dynamic window as well.
		}

		private void ButtonRunWholeTest_Click(object sender, RoutedEventArgs e)
		{
			this.LogStrings.Clear();
			this.WholeTestOptions.Compute(null, this.LogStrings, this.TableFileName.Text);
		}

		private void StartSeries_Click(object sender, RoutedEventArgs e)
		{
			this.SeriesLogStrings.Clear();
		}
	}


	// #############################################################################

	// #############################################################################

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under Microsoft Reciprocal License


Written By
Software Developer (Senior) independent
France France
Hi !

I made my first program on a Sinclair ZX-81.
Since that day, I have the virus of computers. Smile | :)

Here is my website:
https://chrisbertrand.net

And my blog:
https://chrisbertrandprogramer.wordpress.com/

Comments and Discussions