Beispiel #1
0
 public void Remove(IRobot robot)
 {
     var type = robot.GetType();
     if (_robots.ContainsKey(type))
     {
         _robots.Remove(type);
     }
 }
Beispiel #2
0
 public void Add(IRobot robot)
 {
     var type = robot.GetType();
     if (!_robots.ContainsKey(type))
     {
         _robots.Add(type, robot);
     }
 }
        public override void DoService(IRobot robot, int procedureTime)
        {
            base.DoService(robot, procedureTime);
            if (robot.IsChipped)
            {
                var exMsg = String.Format(ExceptionMessages.AlreadyChipped, robot.GetType().Name);
                throw new ArgumentException(exMsg);
            }

            robot.Happiness -= DecreaseHappiness;
            robot.IsChipped  = true;
            this.robots.Add(robot);
        }
Beispiel #4
0
        public static void Replay(this IRobot robot, MethodSignature cachedMethod)
        {
            if (robot == null)
            {
                throw new ArgumentNullException(nameof(robot));
            }

            if (cachedMethod == null)
            {
                throw new ArgumentNullException(nameof(cachedMethod));
            }

            MethodInfo method = robot.GetType().GetMethod(cachedMethod.MethodName);

            if (method != null)
            {
                method.Invoke(robot, cachedMethod.Arguments.ToArray());
            }
        }
Beispiel #5
0
        public static DenominazioneRobot DenominazioneConTimeout(this IRobot robot, TimeSpan timeout)
        {
            //Attenzione: questa implementazione che si avvale dei task
            //serve solo nel momento in cui volete evitare che implementazioni
            //di terze parti influenzino il corretto comportamento del programma
            //per tutti gli altri componenti del software.
            //E' una tecnica di "defensive programming"
            var denominazione = EseguiTaskConTimeout(
                () => new DenominazioneRobot
            {
                Nome         = robot.Nome,
                NomeCompleto = robot.GetType().AssemblyQualifiedName,
                Proprietari  = robot.Proprietari.ToArray()
            },
                () => new DenominazioneRobot(),
                timeout
                );

            return(denominazione);
        }
Beispiel #6
0
 /// <summary>
 /// Return a stringified version of the specified IRobot
 /// </summary>
 /// <param name="robot">The IRobot to stringify</param>
 /// <returns>A stringified version of this Robot</returns>
 public static string ToString(IRobot robot)
 {
     return(robot.GetType() + "[ID=\"" + robot.ID + "\", Name=\"" + robot.Name + "\"]");
 }