Пример #1
0
        private static Event HandleUnloadCommand(UnloadCommand unloadCommand, Dictionary <Product, int> carriedProducts, Drone drone,
                                                 ref Coordinate droneLocation, ref long currentTurn, ref long carriedWeight)
        {
            var distance = droneLocation.CalcEucledianDistance(unloadCommand.Warehouse.Location);

            currentTurn   += ((int)Math.Ceiling(distance)) + 1;
            droneLocation  = unloadCommand.Warehouse.Location;
            carriedWeight -= unloadCommand.Product.Weight * unloadCommand.ProductCount;
            var newCount = carriedProducts.GetOrDefault(unloadCommand.Product, 0) - unloadCommand.ProductCount;

            if (newCount < 0)
            {
                throw new Exception(string.Format("Drone {0} attempted to unload {1} products of type {2} which he doesn't have",
                                                  drone.Index, unloadCommand.ProductCount, unloadCommand.Product.Index));
            }

            carriedProducts[unloadCommand.Product] = newCount;

            var ev = new Event
            {
                Turn             = currentTurn,
                Warehouse        = unloadCommand.Warehouse,
                ProductDelivered = unloadCommand.Product,
                DeliveredCount   = unloadCommand.ProductCount,
                Drone            = drone
            };

            return(ev);
        }
Пример #2
0
        public static async Task <HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "post", Route = "v1/unload")]
            HttpRequestMessage req,
            ILogger logger,
            ExecutionContext context)
        {
            ServiceProvider serviceProvider = Initializer.Initialize(context);

            string body = await req.Content.ReadAsStringAsync().ConfigureAwait(false);

            UnloadCommand command = JsonConvert.DeserializeObject <UnloadCommand>(body);

            if (!command.Validate(out string message))
            {
                return(req.CreateResponse(HttpStatusCode.BadRequest, message));
            }

            IConfiguration config = serviceProvider.GetService <IConfiguration>();
            var            client = new SnowflakeClient(config["ConnectionString"]);
            JObject        result;

            try
            {
                result = client.Unload(command.Stage, command.Query, command.FilePrefix, command.Warehouse, command.Database, command.Schema, command.SingleFile, command.Overwrite);
            }
            catch (Exception e)
            {
                logger.LogError(e, "Error processing request");
                return(req.CreateResponse(HttpStatusCode.InternalServerError, e.Message));
            }

            return(req.CreateResponse <JObject>(HttpStatusCode.OK, result));
        }
Пример #3
0
        public override DronesOutput GetResultFromReader(DronesInput input, TextReader reader)
        {
            var commands     = new List <CommandBase>();
            var commandCount = int.Parse(reader.ReadLine());

            for (int i = 0; i < commandCount; i++)
            {
                var line  = reader.ReadLine();
                var spl   = line.Split(' ');
                var drone = input.Drones[int.Parse(spl[0])];

                var others = spl.Skip(2).Select(int.Parse).ToList();

                CommandBase newCommand;
                switch (spl[1])
                {
                case "D":
                    newCommand = new DeliverCommand(drone, input.Orders[others[0]], input.Products[others[1]], others[2]);
                    break;

                case "W":
                    newCommand = new WaitCommand(drone, (uint)others[0]);
                    break;

                case "U":
                    newCommand = new UnloadCommand(drone, input.WareHouses[others[0]], input.Products[others[1]], others[2]);
                    break;

                case "L":
                    newCommand = new LoadCommand(drone, input.WareHouses[others[0]], input.Products[others[1]], others[2]);
                    break;

                default:
                    throw new ArgumentException(string.Format("Unknown command {0}", spl[1]));
                }

                commands.Add(newCommand);
            }

            return(new DronesOutput {
                Commands = commands
            });
        }
        public override void SetUp()
        {
            base.SetUp();

            _mockRepository = new MockRepository();

            _domainObject1 = DomainObjectMother.CreateFakeObject <Order>();
            _domainObject2 = DomainObjectMother.CreateFakeObject <Order> ();

            _transactionEventSinkWithMock = MockRepository.GenerateStrictMock <IClientTransactionEventSink>();

            _unloadDataCommandMock = _mockRepository.StrictMock <IDataManagementCommand>();

            _unloadCommand = new UnloadCommand(
                new[] { _domainObject1, _domainObject2 },
                _unloadDataCommandMock,
                _transactionEventSinkWithMock);

            _exception1 = new Exception("1");
            _exception2 = new Exception("2");
        }
Пример #5
0
 /// <summary>
 /// The UNLOAD action removes a core from Solr. Active requests will
 /// continue to be processed, but no new requests will be sent to the named core.
 /// If a core is registered under more than one name, only the given name is removed.
 /// </summary>
 /// <param name="coreName">The name of the core to be to be removed. If the persistent
 /// attribute of &lt;solr&gt; is set to "true", the &lt;core&gt; element
 /// with this "name" attribute will be removed from solr.xml.</param>
 /// <param name="delete">If not null, deletes the index once the core is unloaded.  (Only available in 3.3 and above).</param>
 public ResponseHeader Unload(string coreName, UnloadCommand.Delete delete) {
     return SendAndParseHeader(new UnloadCommand(coreName, delete));
 }