old data
This commit is contained in:
@@ -29,170 +29,51 @@
|
||||
//-----------------------------------------------------------------------
|
||||
//-----------------------------------------------------------------------
|
||||
using StgSharp.PipeLine;
|
||||
using StgSharp.Script.Express;
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices.Marshalling;
|
||||
using System.Text;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace StgSharp.Model.Step
|
||||
namespace StgSharp.Modeling.Step
|
||||
{
|
||||
public class StepModel
|
||||
{
|
||||
|
||||
private Dictionary<int, StepEntityBase> _nodes
|
||||
= new Dictionary<int, StepEntityBase>();
|
||||
|
||||
private PipelineScheduler _builder;
|
||||
|
||||
private PipelineScheduler _initScheduler = new PipelineScheduler();
|
||||
private BlueprintScheduler _builder;
|
||||
private Dictionary<int, StepUncertainEntity> _nodes
|
||||
= new Dictionary<int, StepUncertainEntity>();
|
||||
private StepInfo _header;
|
||||
|
||||
internal StepModel( StepInfo header )
|
||||
{
|
||||
_header = header;
|
||||
_builder = new PipelineScheduler();
|
||||
_builder = new BlueprintScheduler();
|
||||
}
|
||||
|
||||
public StepEntityBase? this[ int id ]
|
||||
public StepUncertainEntity this[ int id ]
|
||||
{
|
||||
get
|
||||
{
|
||||
if( id == 0 ) {
|
||||
return null;
|
||||
}
|
||||
if( _nodes.TryGetValue( id, out StepEntityBase? node ) )
|
||||
{
|
||||
if( node is StepUnsupportedEntity ) {
|
||||
throw new StepEntityUnsupportedException();
|
||||
}
|
||||
if( _nodes.TryGetValue( id, out StepUncertainEntity? node ) ) {
|
||||
return node;
|
||||
}
|
||||
node = new StepUninitializedEntity( this, id );
|
||||
_nodes.Add( id, node );
|
||||
node = StepUncertainEntity.Create( id );
|
||||
return node;
|
||||
}
|
||||
private set { _nodes[ id ] = value!; }
|
||||
}
|
||||
|
||||
internal StepEntityBase? this[ ExpSyntaxNode node ]
|
||||
public void AddUncertainEntity( int id, StepUncertainEntity entity )
|
||||
{
|
||||
get
|
||||
{
|
||||
if( node is not StepEntityInstanceNode instance ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
return this[ instance.Id ];
|
||||
}
|
||||
set
|
||||
{
|
||||
if( node is not StepEntityInstanceNode instance ) {
|
||||
throw new InvalidCastException();
|
||||
}
|
||||
this[ instance.Id ] = value;
|
||||
if( _nodes.ContainsKey( id ) ) {
|
||||
throw new InvalidOperationException(
|
||||
"Attempt to add entity with same id more than once" );
|
||||
}
|
||||
_nodes.Add( id, entity );
|
||||
}
|
||||
|
||||
public void BindValue( ExpSyntaxNode node, Action<StepEntityBase> action ) { }
|
||||
|
||||
public StepUninitializedEntity FromInitSequence( StepEntityDefineSequence sequence )
|
||||
public void OrganizeNode()
|
||||
{
|
||||
int id = ( sequence.Expression.Left as StepEntityInstanceNode )!.Id;
|
||||
PipelineNode node;
|
||||
if( _nodes.TryGetValue( id, out StepEntityBase? e ) && e is StepUninitializedEntity u )
|
||||
{
|
||||
u.FromSequence( sequence );
|
||||
node = _initScheduler.GetNode( u.Label );
|
||||
} else
|
||||
{
|
||||
u = new StepUninitializedEntity( this, id );
|
||||
u.FromSequenceUnsafe( sequence );
|
||||
_nodes.Add( id, u );
|
||||
node = _initScheduler.Create( u.Label, u );
|
||||
}
|
||||
|
||||
PipelineNodeInPort port = node.GetInputPort( StepUninitializedEntity.InName );
|
||||
if( sequence.Dependencies.Count() == 0 )
|
||||
{
|
||||
_initScheduler.LinkToInput( port );
|
||||
} else
|
||||
{
|
||||
foreach( int i in sequence.Dependencies )
|
||||
{
|
||||
PipelineNode dNode;
|
||||
StepEntityLabel label = new StepEntityLabel( i );
|
||||
if( _nodes.TryGetValue( i, out e ) )
|
||||
{
|
||||
dNode = _initScheduler.GetNode( label );
|
||||
} else
|
||||
{
|
||||
u = new StepUninitializedEntity( this, i );
|
||||
_nodes.Add( i, u );
|
||||
dNode = _initScheduler.Create( u.Label, u );
|
||||
}
|
||||
port.Connect( dNode.GetOutputPort( StepUninitializedEntity.OutName ) );
|
||||
}
|
||||
}
|
||||
return u;
|
||||
}
|
||||
|
||||
public void InitEntity()
|
||||
{
|
||||
if( _initScheduler is null ) {
|
||||
return;
|
||||
}
|
||||
_initScheduler.ArrangeNodes();
|
||||
PipeLineRunner.Run( _initScheduler );
|
||||
_initScheduler = null!;
|
||||
}
|
||||
|
||||
public void ReplaceEntity(
|
||||
StepUninitializedEntity uninitialized,
|
||||
StepEntityBase accurateEntity )
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull( uninitialized );
|
||||
if( uninitialized.Context != this || accurateEntity.Context != this ) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
if( uninitialized.Id != accurateEntity.Id ) {
|
||||
throw new InvalidOperationException();
|
||||
}
|
||||
_nodes[ uninitialized.Id ] = accurateEntity;
|
||||
}
|
||||
|
||||
public string[] ShowStructure( int depth )
|
||||
{
|
||||
_initScheduler.ArrangeNodes();
|
||||
IEnumerable<PipelineNode> nodes = PipelineMarshal.GetNodeSortedEnumeration(
|
||||
_initScheduler );
|
||||
int count = 0;
|
||||
List<string> info = [
|
||||
@$"Step model root",
|
||||
];
|
||||
foreach( PipelineNode node in nodes )
|
||||
{
|
||||
count++;
|
||||
StepUninitializedEntity uncertain = ( node.NodeOperation as StepUninitializedEntity )!;
|
||||
string[] strings = uncertain.GetEntityDescription( depth - 1 );
|
||||
if( count < nodes.Count() )
|
||||
{
|
||||
info.Add( $" ├-{strings[0]}" );
|
||||
for( int i = 1; i < strings.Length; i++ ) {
|
||||
info.Add( $" | {strings[i]}" );
|
||||
}
|
||||
} else
|
||||
{
|
||||
info.Add( $" └-{strings[0]}" );
|
||||
for( int i = 1; i < strings.Length; i++ ) {
|
||||
info.Add( $" {strings[i]}" );
|
||||
}
|
||||
}
|
||||
}
|
||||
return info.ToArray();
|
||||
foreach( KeyValuePair<int, StepUncertainEntity> node in _nodes ) { }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user