Ejemplo n.º 1
0
 private void GoToChannelCommands()
 {
     if (command.Length > 3)
     {
         throw new ArgumentException("Wrong command");
     }
     else if ("down" == command[2].ToLower())
     {
         if (deviceList[command[0]] is IChannelable)
         {
             IChannelable device = (IChannelable)deviceList[command[0]];
             device.ChannelDown();
         }
         else
         {
             throw new ArgumentException("Wrong device");
         }
     }
     else if ("up" == command[2].ToLower())
     {
         if (deviceList[command[0]] is IChannelable)
         {
             IChannelable device = (IChannelable)deviceList[command[0]];
             device.ChannelUp();
         }
         else
         {
             throw new ArgumentException("Wrong device");
         }
     }
     else
     {
         throw new ArgumentException("Wrong command");
     }
 }
 public IChannelableControl(IEnumerable <Channel> channels, Device device)
 {
     this.channels     = (List <Channel>)channels;
     channelableDevice = (TV)device;
     channelableDevice.SetDefaultCurrentChannel();
     deviceId = device.Id;
     Initializer();
 }
Ejemplo n.º 3
0
        public bool StartChanneling(IChannelable channelable)
        {
            //Make sure we aren't currently channelling anything.
            if (CurrentChannelable != null)
            {
                return(false);
            }

            //Initialise the channel data.
            CurrentChannelable   = channelable;
            RemainingChannelTime = CurrentChannelable.ChannelDuration;

            //Alert any listeners that we have started channeling.
            onStartedChanneling.Raise(CurrentChannelable);

            //We successfully started channelling.
            return(true);
        }
Ejemplo n.º 4
0
 public void ControlWithIChannelable(IChannelable sameDevice)
 {
     Console.WriteLine("Switching channels. \n\nAvailable commands: \n-Set. \n-Increase. \n-Decrease. \n\nEnter your command:");
     Message = Console.ReadLine().ToLower();
     if (Message.Contains("set"))
     {
         Console.WriteLine("Enter channel number (1-100): ");
         int setChannel;
         if (Int32.TryParse(Console.ReadLine(), out setChannel))
         {
             ;
         }
         sameDevice.SetChannel(setChannel);
         if (actWithDevice != null)
         {
             actWithDevice.Invoke((sameDevice.SetChannel(setChannel))); // можно как-то проще?
         }
     }
     else if (Message.Contains("increase"))
     {
         sameDevice.AdjustChannel(true);
         if (actWithDevice != null)
         {
             actWithDevice.Invoke(sameDevice.AdjustChannel(true));
         }
     }
     else if (Message.Contains("decrease"))
     {
         sameDevice.AdjustChannel(false);
         if (actWithDevice != null)
         {
             actWithDevice.Invoke(sameDevice.AdjustChannel(true));
         }
     }
     else
     {
         Console.WriteLine("Nonexistent command");
         if (actWithDevice != null)
         {
             actWithDevice.Invoke("Nonexistent command");
         }
     }
 }