Пример #1
0
 public Robot(IRobotConfiguration configuration, StartArgs startArgs, IPriceManagerBuilder priceManagerBuilder, IDiffer differ)
 {
     _configuration       = configuration;
     _startArgs           = startArgs;
     _priceManagerBuilder = priceManagerBuilder;
     _differ = differ;
 }
Пример #2
0
        /// <summary>
        /// Connect to Vector on the local network using the specified robotConfiguration and IP address
        /// </summary>
        /// <param name="robotConfiguration">The robot configuration.</param>
        /// <param name="ipAddress">The IP address.</param>
        /// <param name="timeout">The timeout.</param>
        /// <returns>A task that represents the asynchronous operation; the task result contains the connected client.</returns>
        public static async Task <Client> Connect(IRobotConfiguration robotConfiguration, IPAddress ipAddress, int timeout)
        {
            var channelCredentials = CreateChannelCredentials(robotConfiguration.Certificate, robotConfiguration.Guid);
            var channel            = await ConnectChannel(channelCredentials, ipAddress.ToString(), robotConfiguration.RobotName, timeout).ConfigureAwait(false);

            return(await ConnectClient(channel, robotConfiguration.Certificate, robotConfiguration.Guid, ipAddress).ConfigureAwait(false));
        }
Пример #3
0
 /// <summary>
 /// Validates the specified robot configuration.
 /// </summary>
 /// <param name="robotConfiguration">The robot configuration.</param>
 /// <returns>A list of errors</returns>
 public static IEnumerable <string> TryValidate(this IRobotConfiguration robotConfiguration)
 {
     if (robotConfiguration == null)
     {
         throw new ArgumentNullException(nameof(robotConfiguration));
     }
     if (string.IsNullOrWhiteSpace(robotConfiguration.RobotName))
     {
         yield return("Robot name is missing");
     }
     if (string.IsNullOrWhiteSpace(robotConfiguration.SerialNumber))
     {
         yield return("Serial number is missing");
     }
     if (string.IsNullOrWhiteSpace(robotConfiguration.Certificate))
     {
         yield return("SSL certificate is missing");
     }
     if (string.IsNullOrWhiteSpace(robotConfiguration.Guid))
     {
         yield return("GUID token is missing");
     }
     if (!RobotNameIsValid(robotConfiguration.RobotName))
     {
         yield return("Invalid robot name. Please match the format exactly. Example: Vector-A1B2");
     }
     if (!SerialNumberIsValid(robotConfiguration.SerialNumber))
     {
         yield return("Serial number is not the correct format.");
     }
 }
 public ColorBuilder(IRobotConfiguration configuration)
 {
     _colorCodes = new Dictionary <string, string>();
     foreach (var colorMapping in configuration.ColorMappings)
     {
         _colorCodes[colorMapping.Name] = colorMapping.Code;
     }
 }
Пример #5
0
 /// <summary>
 /// Finds the current robot address if possible or returns the address from the configuration.
 /// </summary>
 /// <param name="robotConfiguration">The robot configuration.</param>
 /// <returns>A task that represents the asynchronous operation; the task result contains the IP address.</returns>
 public static async Task <IPAddress> FindRobotAddress(this IRobotConfiguration robotConfiguration)
 {
     if (robotConfiguration == null)
     {
         throw new ArgumentNullException(nameof(robotConfiguration));
     }
     return(await FindRobotAddress(robotConfiguration.RobotName).ConfigureAwait(false) ?? robotConfiguration.IPAddress);
 }
Пример #6
0
        public RobotAssembler(IRobotConfiguration configuration, ILogConfiguration logConfiguration, IEnumerable<ComposablePartCatalog> partCatalogs)
        {
            _configuration = configuration;
            _logConfiguiration = logConfiguration;
            _log = _logConfiguiration.CreateLogger("RobotAssembler");

            Compose(partCatalogs);
        }
Пример #7
0
        /// <summary>
        /// Adds the specified robot configuration to the configuration file using the specified SDK configuration file path.
        /// <para>The robot configuration is appended if new or updated if already exists</para>
        /// </summary>
        /// <param name="sdkConfigFilePath">The SDK configuration file path.</param>
        /// <param name="robot">The robot configuration.</param>
        public static void AddOrUpdate(string sdkConfigFilePath, IRobotConfiguration robot)
        {
            var list = new List <IRobotConfiguration>()
            {
                robot
            };

            SaveFile(sdkConfigFilePath, list);
        }
Пример #8
0
        /// <summary>
        /// Validates the specified robot configuration.
        /// </summary>
        /// <param name="robotConfiguration">The robot configuration.</param>
        /// <returns>
        /// The robot configuration unchanged.
        /// </returns>
        /// <exception cref="VectorConfigurationException">Validation error</exception>
        public static IRobotConfiguration Validate(this IRobotConfiguration robotConfiguration)
        {
            var error = TryValidate(robotConfiguration).FirstOrDefault();

            if (string.IsNullOrEmpty(error))
            {
                return(robotConfiguration);
            }
            throw new VectorConfigurationException(error);
        }
Пример #9
0
        public Robot(string name, ILogConfiguration logConfig, IRobotConfiguration configuration, IMessageBus bus, IEnumerable<IPart> parts, IHttpHost httpHost)
        {
            var loggerName = String.Format("Robot.{0}", name);
            _logger = logConfig.CreateLogger(loggerName);

            Name = name;
            Configuration = configuration;
            Parts = parts;
            HttpHost = httpHost;
            Bus = bus;
        }
Пример #10
0
        /// <summary>
        /// Updates the configuration file data
        /// </summary>
        /// <param name="robot">The robot configuration.</param>
        /// <param name="ankiVectorPath">The anki_vector folder path.</param>
        /// <param name="data">The configuration file data.</param>
        private static void WriteConfig(IRobotConfiguration robot, string ankiVectorPath, KeyDataCollection data)
        {
            data[GuidKey] = robot.Guid;
            data[NameKey] = robot.RobotName;
            if (!data.ContainsKey(CertKey))
            {
                data[CertKey] = Path.Combine(ankiVectorPath, robot.RobotName + "-" + robot.SerialNumber + ".cert");
            }
            if (robot.IPAddress != null)
            {
                data[IpKey] = robot.IPAddress.ToString();
            }

            if (!File.Exists(data[CertKey]))
            {
                File.WriteAllText(data[CertKey], robot.Certificate);
            }
        }
Пример #11
0
 public HandlerRegistration(IRobotConfiguration configuration, List<IMessageHandler> handlers)
 {
     _configuration = configuration;
     _handlers = handlers;
 }
Пример #12
0
 /// <summary>
 /// Adds the specified robot configuration to the configuration file using the default SDK configuration file path.
 /// <para>The robot configuration is appended if new or updated if already exists</para>
 /// </summary>
 /// <param name="robot">The robot.</param>
 public static void AddOrUpdate(IRobotConfiguration robot)
 {
     AddOrUpdate(DefaultSdkConfigFilePath, robot);
 }
Пример #13
0
 public RobotAssembler(IRobotConfiguration configuration, ILogConfiguration logConfiguration, IEnumerable<Assembly> partAssemblies, IEnumerable<string> partDirectories)
     : this(configuration, logConfiguration, BuildCatalogs(partAssemblies, partDirectories))
 {
 }
Пример #14
0
 public RobotAssembler(IRobotConfiguration configuration, ILogConfiguration logConfiguration, IEnumerable<Assembly> partAssemblies)
     : this(configuration, logConfiguration, partAssemblies, Enumerable.Empty<string>())
 {
 }
Пример #15
0
 public RobotAssembler(IRobotConfiguration configuration, ILogConfiguration logConfiguration, IEnumerable<string> partDirectories)
     : this(configuration, logConfiguration, Enumerable.Empty<Assembly>(), partDirectories)
 {
 }
Пример #16
0
 public RobotAssembler(IRobotConfiguration configuration, ILogConfiguration logConfiguration)
     : this(configuration, logConfiguration, Enumerable.Empty<Assembly>(), Enumerable.Empty<string>())
 {
 }