示例#1
0
        static void Main(string[] args)
        {
            //List<int> list = new List<int>();
            //LinkedList<int> l = new LinkedList<int>();
            //IEnumerable<int> a = l;
            //var b = list as IEnumerable<int>;


            Dog   dog   = new Dog();
            Horse horse = new Horse();

            Cat cat = new Cat();

            ICommunicate iCat = cat as ICommunicate;

            Say(iCat);

            ICommunicate iDog = dog as ICommunicate;  //explicit boxing

            Say(iDog);

            ICommunicate iHorse = horse;              //implicit boxing

            Say(iHorse);
            Say(horse);   //implicit boxing


            Horse horse1 = (Horse)iHorse; //unboxing
            Dog   dog1   = (Dog)iHorse;   //unboxing //exception
        }
 public SecurePayGateway(ICommunicate endpoint, string merchantId, string merchantPassword, string apiUri)
 {
     _endpoint = endpoint;
     _merchantId = merchantId;
     _password = merchantPassword;
     _connectionTimeoutSeconds = 60;
     _apiUri = apiUri;
 }
 public void OnPlayerCommunicate()
 {
     if (CurrentCharacter != null && CurrentCharacter is ICommunicate)
     {
         ICommunicate spokesperson = CurrentCharacter as ICommunicate;
         _currentLocation.Message = spokesperson.CurrentMessage();
     }
 }
        public void Fixture()
        {
            _fakeCommunicationMechanism = Substitute.For<ICommunicate>();

            _gateway = new SecurePayGateway(_fakeCommunicationMechanism, "ABC0001", "abc123", ApiPeriodic);

            _card = new SecurePayCardInfo { Number = "4444333322221111", ExpiryMonth = 10, ExpiryYear = 15 };
        }
示例#5
0
        /// <summary>
        /// initialize the Configuration Parameters, timer and other data
        /// </summary>
        /// <param name="constConfigurationParameters"></param>
        /// <param name="myInterface">Interface</param>
        public Manager(ConfigurationParameters constConfigurationParameters, ICommunicate Comunicate)
        {
            _configurationParameters = constConfigurationParameters;
            InitData();
            _comunicate = Comunicate;

            DateTime tomorrow = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day, 0, 0, 0).AddDays(1);
            TimeSpan due      = tomorrow.Subtract(DateTime.Now);
            TimeSpan period   = new TimeSpan(_configurationParameters.CheckFrequency, 0, 0, 0);

            _timer = new System.Threading.Timer(DeletionEventHandler, null, due, period);
        }
示例#6
0
        public Manager(ICommunicate myBox, ConfigurationData configurationData)
        {
            _mainTree   = new BST <Width>();
            _timeList   = new Linked_List <TimeData>();
            _printBox   = myBox;
            _configData = configurationData;

            DateTime tomorrow = new DateTime(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day).AddDays(1);
            TimeSpan due      = tomorrow - DateTime.Now;
            TimeSpan period   = new TimeSpan(_configData.FrequencyCheck, 0, 0, 0);

            _timer = new Timer(RemovingEventHandler, null, due, period); //Initiazling the timer
        }
示例#7
0
        /// <summary>
        /// Contructor of <see cref="GoFishController"/>
        /// </summary>
        /// <param name="comm"></param>
        public GoFishController(ICommunicate comm) : base(comm)
        {
            SocketHandler CommHandler = (SocketHandler)comm;

            SocketHandler = CommHandler;

            // Subscribe to collection
            // Make a collection to observe and add a few Person objects.
            // Wire up the CollectionChanged event.

            //ListOfGameRequests = CommHandler.GetGameRequests();
            ListOfGameRequests = new List <GameRequest>();

            CommHandler.ListOfGameRequests.CollectionChanged += GameRequests_CollectionChanged;

            // Start thread that handles GameRequests
            Thread gameRequestThread = new Thread(HandleGameRequests);

            gameRequestThread.Start();
        }
 public void CommunicateSing(ICommunicate region)
 {
     region.Sing();
 }
 public void CommunicateTalk(ICommunicate region)
 {
     region.Talk();
 }
示例#10
0
 public void SetCommunicationMeans(ICommunicate communicationMeans)
 {
     this.communicationMeans = communicationMeans;
 }
示例#11
0
 /// <summary>
 /// Constructor for the <see cref="GameController"/> class.
 /// </summary>
 /// <param name="comm">Object which implements ICommunicate</param>
 public GameController(ICommunicate comm)
 {
     CommHandler = comm;
     Games       = new List <CardGame>();
 }
示例#12
0
 /// <summary>
 /// construct and communicate via LAN (TCP/IP)
 /// </summary>
 /// <param name="hostname">ip address of ecr device</param>
 public Dp25(string hostname, int port)
 {
     _communicator = new LANCommunicator(hostname, port);
 }
示例#13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Spel"/> class.
 /// </summary>
 /// <param name="communicator">Communicator.</param>
 public Spel(ICommunicate communicator)
 {
     this.communicator = communicator;
     this.HuidigeHand  = null;
     this.Handen       = new List <Hand>();
 }
示例#14
0
文件: Butler.cs 项目: SaumilP/tryouts
 public Butler(IWeapon weapon, ICommunicate communicate)
 {
     _weapon      = weapon;
     _communicate = communicate;
 }
示例#15
0
 public static void Say(ICommunicate communicate)
 {
     communicate.Voice();
 }
示例#16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="InitialiseerDeTafel"/> class.
 /// </summary>
 /// <param name="communicate">De communicator.</param>
 public InitialiseerDeTafel(ICommunicate communicate)
 {
     this.communicator = communicate;
 }
示例#17
0
        static void Main(string[] args)
        {
            // Make a fixed size array of string data.
            string[] dumbArray = { "First", "Second", "Third" };
            DisplayData(dumbArray);

            try
            {
                // While you can modify an existing item in the array ...
                dumbArray[0] = "One";
                dumbArray[1] = "Two";
                dumbArray[2] = "Three";
                DisplayData(dumbArray);

                // The array is NOT flexible. It will not grow dynamically!
                dumbArray[3] = "Four";
                DisplayData(dumbArray);
            }
            catch (Exception Err)
            {
                Console.WriteLine(Err.Message);
            }


            // Because the non-generic collection ArrayList allows you to add
            // ANY type of object, it leads to confusion because you never
            // know what type of object you're dealing with as you iterate through
            // the collection.
            ArrayList strArray = new ArrayList();

            strArray.AddRange(new string[] { "First", "Second", "Third" });
            strArray.Add(23);
            strArray.Add(8.97);
            strArray.Add(true);
            Car c = new Car {
                Manufacturer = "Ford", Model = "Focus"
            };

            strArray.Add(c);

            // Although value types (like int and bool) can be displayed properly
            // (because they have ToString() override implemented), reference types
            // (like our "Car" class) do not have this override by default. As a result
            // the "Car" class DOES NOT display its contents correctly. Instead the object
            // type "Generics.Car" is displayed.
            object[] fromList = strArray.ToArray();
            DisplayData(fromList);

            // Although the integer values 23 exists in the collection and it's value
            // can be displayed as a string, it will NOT compare as equal to the string "23".
            // More confusion!
            bool IsEqual = CheckForEquality(fromList, "23");

            Console.WriteLine($"Check for equality results are: {IsEqual}\r\n================================");

            // Create some Car objects that we'll use in both the non-generic as well as generic collections
            Car ford = new Car {
                Manufacturer = "Ford", Model = "Focus"
            };
            Car gmc = new Car {
                Manufacturer = "GMC", Model = "Journey"
            };
            Car honda = new Car {
                Manufacturer = "Honda", Model = "Civic"
            };

            // Let's use our hand coded "NonGenericCarCollection"
            NonGenericCarCollection nonGenericCarCollection = new NonGenericCarCollection();

            nonGenericCarCollection.Add(ford);
            nonGenericCarCollection.Add(gmc);
            nonGenericCarCollection.Add(honda);
            nonGenericCarCollection.Display();
            Console.WriteLine($"Removing {honda.Manufacturer}:{honda.Model}");
            nonGenericCarCollection.Remove(honda);
            nonGenericCarCollection.Display();


            Console.WriteLine("Demonstrate that using non-generic methods require a lot of hand coding and are not very flexible.");
            Console.WriteLine("========================================");

            // Here we demonstrate how to use a hand-coded class to swap various values.
            // Only the types the have been coded into the NonGenericSwap can make use of the "Swap" method.
            // We would not for example be able to swap two floating point numbers using this class!
            int a = 9, b = 6;

            Console.WriteLine($"a={a} b={b}");
            NonGenericSwap.Swap(ref a, ref b);
            Console.WriteLine($"a={a} b={b}");

            Console.WriteLine($"car a={ford.Manufacturer} car b={gmc.Manufacturer}");
            NonGenericSwap.Swap(ref ford, ref gmc);
            Console.WriteLine($"car a={ford.Manufacturer} car b={gmc.Manufacturer}");

            bool ok = true, notOk = false;

            Console.WriteLine($"ok={ok} notOk={notOk}");
            NonGenericSwap.Swap(ref ok, ref notOk);
            Console.WriteLine($"ok={ok} notOk={notOk}");

            // This example will not compile using the NonGenericSwap class
            float f1 = 9.87f;
            float f2 = 2.34f;

            //NonGenericSwap.Swap(ref f1, ref f2);


            // Reset all variables to their original values so we can run the same tests using generics
            a     = 9;
            b     = 6;
            ok    = true;
            notOk = false;
            NonGenericSwap.Swap(ref ford, ref gmc);

            //------------- Introducing Generics ----------------------------------
            Console.WriteLine("Now, WITHOUT CREATING ANY NEW CODE, we can use generics to create a type-safe collection of Car objects!");
            List <Car> genericCarCollection = new List <Car>();

            genericCarCollection.Add(ford);
            genericCarCollection.Add(gmc);
            genericCarCollection.Add(honda);
            genericCarCollection.Display();
            Console.WriteLine($"Removing {honda.Manufacturer}:{honda.Model}");
            genericCarCollection.Remove(honda);
            genericCarCollection.Display();

            Console.WriteLine("Demonstrate that writing a custom generic can help simplify your code.");

            // Notice that we can now swap not only all of the previous data types, but also ANY other type
            Console.WriteLine("========================================");
            Console.WriteLine($"a={a} b={b}");
            GenericSwap.Swap(ref a, ref b);
            Console.WriteLine($"a={a} b={b}");

            Console.WriteLine($"car a={ford.Manufacturer} car b={gmc.Manufacturer}");
            GenericSwap.Swap(ref ford, ref gmc);
            Console.WriteLine($"car a={ford.Manufacturer} car b={gmc.Manufacturer}");

            Console.WriteLine($"ok={ok} notOk={notOk}");
            GenericSwap.Swap(ref ok, ref notOk);
            Console.WriteLine($"ok={ok} notOk={notOk}");

            // This example would not compile using the NonGenericSwap class.
            Console.WriteLine($"f1={f1} f2={f2}");
            GenericSwap.Swap(ref f1, ref f2);
            Console.WriteLine($"f1={f1} f2={f2}");
            Console.WriteLine("========================================");

            // Demonstrates how we add constraints to a generic class in order
            // to tell the compiler more details about the type being used
            ICommunicate fluffy = new Cat {
                Name = "Fluffy", Message = "Meaow"
            };
            ICommunicate rover = new Dog {
                Name = "Rover", Message = "Bark"
            };

            GenericSwap.SwapMessage(fluffy, rover);

            // NOTE: The previous method call and the one commented out below are functionally equivalent.
            //       When you invoke generic methods such as SwapMessage<T>, you can optionally omit the type parameter if (and only
            //       if) the generic method requires arguments because the compiler can infer the type parameter based on the
            //       member parameters.
            //
            // GenericSwap.SwapMessage<ICommunicate>(fluffy, rover);



            DoubleLinkedList <string, int> intList = new DoubleLinkedList <string, int>();

            intList.Append("One", 1);
            intList.Append("Two", 2);
            intList.Append("Three", 3);
            intList.Append("Four", 4);
            intList.Append("Five", 5);
            intList.Append("Six", 6);
            intList.Remove("Four");
            intList.InsertAfter("Three", "Four", 4);
            intList.Append("Seven", 7);
            intList.Append("Eight", 8);
            intList.Remove("One");
            intList.Remove("Eight");
            intList.InsertAfter("Seven", "Last", 999);

            Console.WriteLine($"{intList}");
            Console.WriteLine($"Value at Six={intList["Six"].Value}");


            DoubleLinkedList <int, double> doubleList = new DoubleLinkedList <int, double>();

            doubleList.Append(1, 1.12);
            doubleList.Append(2, 87.4);
            doubleList.Append(3, 92.6);
            doubleList.Append(4, 15.4);
            doubleList.Append(5, 12.66);
            doubleList.Append(6, 9.3);
            doubleList.Append(7, 2.3);
            doubleList.Remove(4);
            doubleList.Remove(3);
            doubleList.InsertAfter(2, 3, 99.99);

            Console.WriteLine($"{doubleList}");
            Console.WriteLine($"Value at 6={doubleList[6].Value}");

            Console.WriteLine("Enumerating entire list ==============================");
            foreach (IDataNode <int, double> node in doubleList)
            {
                Console.WriteLine($"{node.Key}={node.Value}");
            }


            DoubleLinkedList <int, string> stringList = new DoubleLinkedList <int, string>();

            stringList.Append(1, "Hello");
            stringList.Append(2, "There");
            stringList.Append(3, "Everyone");
            stringList.Remove(3);
            stringList.InsertAfter(2, 3, "Bob");
            Console.WriteLine($"{stringList}");
            Console.WriteLine($"Last node in stringList {stringList.TerminalNode.Key}={stringList.TerminalNode.Value}\r\n\r\n");


            Console.WriteLine("Demonstrate factory pattern using generics===============");

            ICommunicate[] LetsTalk = new ICommunicate[2];
            LetsTalk[0] = ObjectFactory.Create <Dog>("Rex");
            LetsTalk[1] = ObjectFactory.Create <Cat>("Fluffy");

            foreach (ICommunicate speaker in LetsTalk)
            {
                speaker.Speak();
            }



            Console.ReadKey();
        }
示例#18
0
 public Latter(ICommunicate author, ICommunicate target, string content)
 {
     this.Author  = author;
     this.Target  = target;
     this.content = content;
 }
示例#19
0
 /// <summary>
 /// construct and communicate via COM (RS232 Serial Port)
 /// </summary>
 /// <param name="portName"></param>
 public Dp25(string portName)
 {
     _communicator = new SerialCommunicator(portName);
 }
示例#20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BlackjackController"/> class.
 /// </summary>
 /// <param name="tafel">Huidige tafel.</param>
 /// <param name="communicator">De communicator.</param>
 public BlackjackController(Tafel tafel, ICommunicate communicator)
 {
     this.communicator = communicator;
     this.spel         = new Spel(communicator);
     this.tafel        = tafel;
 }
示例#21
0
 public LucidReplicatedStateMachine(IMemoryCache store, ICommunicate communicate, IOptionsMonitor <LucidUrls> urls)
 {
     _store       = store;
     _communicate = communicate;
     _urls        = urls.CurrentValue;
 }