2019-04-06 13:34:30 +02:00
using System ;
2019-04-09 16:14:26 +02:00
using System.Diagnostics ;
2019-04-06 13:34:30 +02:00
using System.Runtime.CompilerServices ;
2019-04-09 16:14:26 +02:00
using System.Security.Cryptography.X509Certificates ;
using VCRlogic ;
2019-04-06 13:34:30 +02:00
2019-04-09 16:14:26 +02:00
namespace VCRlogic
2019-04-06 13:34:30 +02:00
{
2019-04-09 16:14:26 +02:00
public static class SMtape
2019-04-06 13:34:30 +02:00
{
2019-04-09 16:14:26 +02:00
private static StateTape _concreteState ;
public delegate void TapeEventHandler ( ) ;
public static event TapeEventHandler evIntape ;
public static event TapeEventHandler evOuttape ;
2019-04-09 17:29:40 +02:00
public static event TapeEventHandler evEndtape ;
public static event TapeEventHandler evNoendtape ;
2019-04-09 16:14:26 +02:00
public static void initSMtape ( )
{
setState ( new StapeNoTapeIn ( ) ) ;
}
public static void setState ( StateTape e )
{
_concreteState = null ;
_concreteState = e ;
}
public static void insertTape ( )
{
if ( evIntape ! = null )
{
evIntape ( ) ;
}
}
public static void ejectTape ( )
{
if ( evOuttape ! = null )
{
evOuttape ( ) ;
}
2019-04-09 17:29:40 +02:00
}
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
public static void endTape ( )
{
if ( evEndtape ! = null )
{
evEndtape ( ) ;
}
}
public static void notEndTape ( )
{
if ( evNoendtape ! = null )
{
evNoendtape ( ) ;
}
2019-04-09 16:14:26 +02:00
}
2019-04-06 13:34:30 +02:00
}
2019-04-09 17:29:40 +02:00
public abstract class StateTape
{
public abstract void evIntape ( ) ;
2019-04-06 13:34:30 +02:00
2019-04-09 17:29:40 +02:00
public abstract void evOuttape ( ) ;
2019-04-06 14:10:00 +02:00
2019-04-09 17:29:40 +02:00
public abstract void evEndtape ( ) ;
2019-04-06 14:10:00 +02:00
2019-04-09 17:29:40 +02:00
public abstract void evNotendtape ( ) ;
}
2019-04-06 14:10:00 +02:00
2019-04-09 17:29:40 +02:00
public class StapeNoTapeIn : StateTape
2019-04-09 16:14:26 +02:00
{
2019-04-09 17:29:40 +02:00
public StapeNoTapeIn ( )
{
Debug . Print ( "NoTapeIn\n" ) ;
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
// sub to event
SMtape . evIntape + = evIntape ;
}
public override void evIntape ( )
{
//unsub
SMtape . evIntape - = evIntape ;
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
SMtape . setState ( new StapeTapeInNotEnd ( ) ) ;
}
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
public override void evOuttape ( )
{
}
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
public override void evEndtape ( )
{
2019-04-06 13:34:30 +02:00
2019-04-09 17:29:40 +02:00
}
2019-04-06 13:34:30 +02:00
2019-04-09 17:29:40 +02:00
public override void evNotendtape ( )
{
}
2019-04-09 16:14:26 +02:00
}
2019-04-09 17:29:40 +02:00
public class StapeTapeInNotEnd : StateTape
2019-04-09 16:14:26 +02:00
{
2019-04-09 17:29:40 +02:00
public StapeTapeInNotEnd ( )
{
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
Debug . Print ( "TapeInNotEnd\n" ) ;
//sub
SMtape . evOuttape + = evOuttape ;
SMtape . evEndtape + = evEndtape ;
}
public override void evIntape ( )
{
}
public override void evOuttape ( )
{
//unsub
SMtape . evOuttape - = evOuttape ;
SMtape . evEndtape - = evEndtape ;
SMtape . setState ( new StapeNoTapeIn ( ) ) ;
}
public override void evEndtape ( )
{
//unsub
SMtape . evOuttape - = evOuttape ;
SMtape . evEndtape - = evEndtape ;
SMtape . setState ( new StapeTapeInEnd ( ) ) ;
}
public override void evNotendtape ( )
{
}
2019-04-09 16:14:26 +02:00
}
2019-04-06 13:34:30 +02:00
2019-04-09 16:14:26 +02:00
2019-04-09 17:29:40 +02:00
public class StapeTapeInEnd : StateTape
2019-04-09 16:14:26 +02:00
{
2019-04-09 17:29:40 +02:00
public StapeTapeInEnd ( )
{
Debug . Print ( "TapeInEnd\n" ) ;
SMtape . evOuttape + = evOuttape ;
SMtape . evNoendtape + = evNotendtape ;
}
public override void evIntape ( )
{
}
public override void evOuttape ( )
{
SMtape . evOuttape - = evOuttape ;
SMtape . evNoendtape - = evNotendtape ;
SMtape . setState ( new StapeNoTapeIn ( ) ) ;
}
public override void evEndtape ( )
{
}
public override void evNotendtape ( )
{
SMtape . evOuttape - = evOuttape ;
SMtape . evNoendtape - = evNotendtape ;
SMtape . setState ( new StapeTapeInNotEnd ( ) ) ;
}
}
}