//.################################################
//# Copyright © 2006-2010 Evolving Software Ltd   #
//# Author: Vijay Patel                           #
//################################################'

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;

using Evolving.DomainTypes;
using Evolving.TrueView.Domain.Attributes;
using Evolving.TrueView.UI;

using System.Diagnostics;
using System.Reflection;
using TestApplicationDomainModel.Objects;

namespace TestApplicationDomainModel
{
    /// <summary>
    /// A set of methods
    /// </summary>
    [Serializable]
    [ObjectInstance(IsPersistable = false)]
    public class MethodTests
    {
        public Guid ID { get; internal set; }

        /// <summary>
        /// This method returns no value.
        /// It should appear with a 'ready to invoke' icon.
        /// </summary>
        public void MethodWithNoReturnValue()
        {
            Trace.TraceInformation(MethodBase.GetCurrentMethod().Name);
        }

        /// <summary>
        /// This method accepts a single parameter.
        /// It should appear with a 'disabled' icon.
        /// </summary>
        /// <param name="aString"></param>
        public void MethodWithOneParameter(string aString)
        {
            Trace.TraceInformation(MethodBase.GetCurrentMethod().Name);
        }

        /// <summary>
        /// This method accepts multiple parameters.
        /// It should appear with a 'disabled' icon.
        /// </summary>
        /// <param name="aString">This should accept a String</param>
        /// <param name="aNumber">This should accept an Integer</param>
        /// <param name="aDate">This should accept a Date</param>
        /// /// <param name="category">This should accept a Category</param>
        public void MethodWithMultipleParameters(string aString, int aNumber, DateTime aDate, Category category)
        {
            Trace.TraceInformation(MethodBase.GetCurrentMethod().Name);
        }

        /// <summary>
        /// This method simply returns a string.
        /// It should appear with a 'ready to invoke' icon.
        /// </summary>
        /// <returns></returns>
        public string MethodThatReturnsA_String()
        {
            return "This is a string";
        }

        /// <summary>
        /// This method returns an Entity.
        /// It should appear with a 'ready to invoke' icon.
        /// </summary>
        /// <returns></returns>
        public MethodTests MethodThatReturnsAnEntity()
        {
            return new MethodTests();
        }

        /// <summary>
        /// This method takes 10 seconds to run.
        /// The execution happens on a separate thread.
        /// This button has a custom icon.
        /// </summary>
        [Method(IsThreadSafe = true)]
        public void LongRunningAsyncMethod()
        {
            var runFor = TimeSpan.FromSeconds(10);
            var runUntil = DateTime.Now.Add(runFor);

            while (DateTime.Now < runUntil)
            {
                System.Threading.Thread.Sleep(1000);
                Trace.TraceInformation("Running...");
            }
        }

        /// <summary>
        /// This method takes 10 seconds to run.
        /// The execution happens on the same thread (the UI is blocked until the method finishes).
        /// </summary>
        /// <returns></returns>
        [Method(IsThreadSafe = false)]
        public string LongRunningSyncMethod()
        {
            var runFor = TimeSpan.FromSeconds(10);
            var runUntil = DateTime.Now.Add(runFor);

            while (DateTime.Now < runUntil)
            {
                System.Threading.Thread.Sleep(1000);
                Trace.TraceInformation("Running...");
            }

            return MethodBase.GetCurrentMethod().Name;
        }

    }
}
