Beispiel #1
0
        private static int Main(string[] args)
        {
            var parser = new Parser(_ => new ParserSettings {
                HelpWriter = null
            });
            var result = parser.ParseArguments <Options>(args);

            logger.Info("Beginning");
            Console.WriteLine("Beginning");

            return(result.MapResult(opts => Run(opts), errs => {
                Console.WriteLine(errs.ToString());
                return ErrorExitStatus;
            }));
        }
        private Connection CreateConnection(string hostname, ushort port, string workerId)
        {
            Connection conn;

            var connectionParameters = new ConnectionParameters
            {
                WorkerType = _workerType,
                Network    =
                {
                    ConnectionType = NetworkConnectionType.Tcp,
                    Tcp            = new TcpNetworkParameters()
                    {
                        MultiplexLevel = 1
                    }
                }
            };

            using (var future = Connection.ConnectAsync(hostname, port, workerId, connectionParameters))
            {
                conn = future.Get();
            }

            _logger.Info("Successfully connected using the Receptionist");

            return(conn);
        }
        private Hashing.Hash128 GetModelHash(string model)
        {
            return(_modelHash.GetOrAdd(model, (modelPath) =>
            {
                var hb = Hashing.Builder();
                if (!Buffers.TryTake(out var buffer))
                {
                    buffer = new byte[1024];
                }
                using (var stream = OpenModelReader(modelPath))
                {
                    while (true)
                    {
                        var count = stream.Read(buffer, 0, buffer.Length);
                        if (count <= 0)
                        {
                            break;
                        }
                        for (var i = 0; i < count; i++)
                        {
                            hb.Add(buffer[i]);
                        }
                    }
                }

                Buffers.Add(buffer);

                var hash = hb.Build();
                if (DebugFlags.Debug(typeof(DerivedModelManager)))
                {
                    _log.Info($"Generated model hash for {model} = {hash}");
                }
                return hash;
            }));
Beispiel #4
0
        private void OnFlagUpdate(FlagUpdateOp op)
        {
            if (_names.Contains(op.Name))
            {
                if (op.Value.HasValue)
                {
                    _values[op.Name] = op.Value.Value;
                    _logger.Info($"Flag updated: {op.Name} = {op.Value.Value}");
                }
                else if (_values.ContainsKey(op.Name))
                {
                    _values.Remove(op.Name);
                    _logger.Info($"Flag unset: {op.Name}");
                }

                SetValue(Recompute());
            }
        }
        /// <summary>
        /// Constructs a GenericWorker. Initializes a <see cref="WorkerContext"/> given the parameters.
        /// </summary>
        /// <param name="workerType">Type of worker</param>
        /// <param name="workerId">Unique ID of worker</param>
        /// <param name="hostname">SpatialOS deployment hostname</param>
        /// <param name="port">SpatialOS deployment port</param>
        protected GenericWorker(string workerType, string workerId, string hostname, ushort port)
        {
            _workerId   = workerId;
            _workerType = workerType;

            WorkerContext.GetInstance().Init(workerType, workerId, hostname, port);

            _logger.Info("Initialized Deployment Context");
        }