using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CategoryTheory;
using DiagramUI.Labels;
using DiagramUI;
using DiagramUI.Interfaces;
using DataPerformer.Interfaces;
using DataPerformer.Helpers;
namespace DataPerformer.Runtime
{
/// <summary>
/// Simplest runtime fatory
/// </summary>
public class DataPerformerRuntimeFactory : IDataPerformerRuntimeFactory
{
#region Fields
/// <summary>
/// Singleton
/// </summary>
public static readonly DataPerformerRuntimeFactory Object = new DataPerformerRuntimeFactory();
private ITimeMeasureProvider provider = new TimeMeasureProvider();
/// <summary>
/// Check level
/// </summary>
protected int priority = 0;
#endregion
#region Ctor
/// <summary>
/// Default constructor
/// </summary>
protected DataPerformerRuntimeFactory()
{
}
#endregion
#region IDataPerformerRuntimeFactory Members
/// <summary>
/// Creates runtime from collection
/// </summary>
/// <param name="collection">The collection</param>
/// <param name="priority">Priority</param>
/// <returns>The runtime</returns>
public virtual IDataPerformerRuntime Create(IComponentCollection collection, int priority)
{
return new DataPerformerRuntime(collection, priority);
}
/// <summary>
/// Time provider
/// </summary>
ITimeMeasureProvider IDataPerformerRuntimeFactory.TimeProvider
{
get { return provider; }
}
/// <summary>
/// Creates collection
/// </summary>
/// <param name="consumer">Data consumer</param>
/// <param name="priority">Priority</param>
/// <returns>Collection</returns>
public virtual IComponentCollection CreateCollection(IDataConsumer consumer, int priority)
{
Action<object> act = (object obj)=>{};
List<object> list = new List<object>();
return CreateCollection(consumer, list, act, priority);
}
/// <summary>
/// Level of check
/// </summary>
public int Priority
{
get { return priority; }
set { priority = value; }
}
#endregion
#region Specific Members
#region Public Members
/// <summary>
/// Gets differential equation solver from object
/// </summary>
/// <param name="obj">The object</param>
/// <returns>The solver</returns>
public virtual IDifferentialEquationSolver GetDifferentialEquationSolver(object obj)
{
return null;
}
#endregion
#region Protected Members
/// <summary>
/// Creates component collection
/// </summary>
/// <param name="consumer">Data consumer</param>
/// <param name="list">List of objects</param>
/// <param name="action">Action</param>
/// <param name="priority">Priorty</param>
/// <returns>Component collection</returns>
protected IComponentCollection CreateCollection(IDataConsumer consumer, List<object> list, Action<object> action, int priority)
{
CreateDataConsumerCollection(consumer, list, action, priority);
IDesktop desktop = (consumer as IAssociatedObject).GetDesktop();
return new ComponentCollection(list, desktop);
}
/// <summary>
/// Creates collection of components
/// </summary>
/// <param name="consumer">Data consumer</param>
/// <param name="list">List of objects</param>
/// <param name="action">Additional acton</param>
/// <param name="priority">Priority</param>
/// <returns>Collection of components</returns>
protected void CreateDataConsumerCollection(IDataConsumer consumer, List<object> list,
Action<object> action, int priority)
{
IList ll = consumer.GetDependentObjects();
foreach (object o in ll)
{
if (o is INamedComponent)
{
action(o);
if (!list.Contains(o))
{
list.Add(o);
}
continue;
}
if (o is IAssociatedObject)
{
IAssociatedObject ao = o as IAssociatedObject;
object ob = ao.Object;
action(ob);
if (ob is INamedComponent)
{
if (!list.Contains(ob))
{
list.Add(ob);
}
continue;
}
}
}
}
#endregion
#endregion
}
}