Ejemplo n.º 1
0
        static void Main()
        {
            string tsMsg = TimeStampSource.IsHighPrecision
                ? "This demonstration has HIGH PRECISION timestamps."
                : "This demonstration has LOW PRECISION timestamps.";

            Console.WriteLine("Beginning quick start demo.  " + tsMsg);
            TimeStampSource.Calibrate();
            DateTime demoStart = TimeStampSource.Now;

            DemonstrateBasicVault();
            Console.WriteLine();
            Console.WriteLine();

            DemonstrateMutableResourceVault();
            Console.WriteLine();
            Console.WriteLine();

            Console.WriteLine("Begin ReadWriteVault demo.");
            string   res = ReadWriteVaultDemo.RunDemo(TimeSpan.FromDays(7.5));
            FileInfo fi  = new FileInfo(ReadWriteDemoVaultOutputFilePath);

            {
                using var sw = fi.CreateText();
                sw.Write(res);
            }
            Console.WriteLine($"ReadWriteVault demo completed and log written to [{fi.FullName}].");
            Console.WriteLine();
            Console.WriteLine();

            DateTime demoEnd = TimeStampSource.Now;

            Console.WriteLine("All three demos completed ok.");
            Console.WriteLine($"Elapsed milliseconds: [{(demoEnd - demoStart).TotalMilliseconds:F3}].");
        }
Ejemplo n.º 2
0
        public static string RunDemo(TimeSpan wait)
        {
            if (wait <= TimeSpan.Zero)
            {
                throw new ArgumentNotPositiveException <TimeSpan>(nameof(wait), wait);
            }
            ReadWriteVaultDemo d = new ReadWriteVaultDemo();

            //start the demos master thread (which will start other threads and wait for them to complete or timeout)
            d._masterThread.Start(wait);
            //join the master thread -- will end when demo completes, timeouts or otherwise faults
            d._masterThread.Join();
            try
            {
                //dispose logger
                d._log.Dispose();
            }
            catch
            {
                //eat
            }

            try
            {
                //signal cancel on token
                d._cts.Cancel();
            }
            catch
            {
                //eat
            }

            try
            {
                //dispose token
                d._cts.Dispose();
            }
            catch
            {
                //eat
            }
            //return the logged info from the disposed log if available
            return(d._log.Text ?? string.Empty);
        }