Tuesday, April 24, 2012

Sequence Diagram

Here is the original Visio diagram

Here is Scanner.css

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SequenceTest
{
    class Scanner
    {
        Scan scan;
        string doorState;

        public string DoorState
        {
            get { return doorState; }
            set { doorState = value; }
        }

        public Scanner(string cardNumber, string scannerNumber)
        {
            scan = new Scan();
            scan.CardNumber = cardNumber;
            scan.ScannerNumber = scannerNumber;
            scan.ScanTime = DateTime.Now;
            DoorState="Closed";
            ValidateScan();
        }

        private bool ValidateScan()
        {
            bool valid = false;
            Validator validator = new Validator(scan);
            valid = validator.ScanValidation();
            if (valid)
                DoorState = "open";
            return valid;
        }


    }
}


Here is the code for scan.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SequenceTest
{
    public class Scan
    {
        private string cardNumber;

        public string CardNumber
        {
            get { return cardNumber; }
            set { cardNumber = value; }
        }
        private string scannerNumber;

        public string ScannerNumber
        {
            get { return scannerNumber; }
            set { scannerNumber = value; }
        }
        private DateTime scanTime;

        public DateTime ScanTime
        {
            get { return scanTime; }
            set { scanTime = value; }
        }
    }
}


Here is the Validator.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SequenceTest
{
    class Validator
    {
        Scan scan;

        public Validator(Scan s)
        {
            scan = s;
        }

        public bool ScanValidation()
        {
            bool isvalid = false;
            if (scan.CardNumber.Equals("100")
                && scan.ScanTime.ToShortDateString().Equals("4/24/2012"))
            {
                isvalid = true;
            }

            return isvalid;
        }
    }
}



Here is Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SequenceTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Scanner s = new Scanner("100", "1");
            Console.WriteLine(s.DoorState);

            Console.ReadKey();
        }
    }
}


Here is the Sequence diagram generated by Visual Studio


Here are the Visual Studio generated class diagrams

No comments:

Post a Comment