コード例 #1
0
ファイル: IANormal.cs プロジェクト: bobemv/swarm
    void SearchTargets(Unit unit)
    {
        float minDistance = Mathf.Infinity;
        Unit  target      = null;

        for (int i = 0; i < _playManager.allyUnits.Count; i++)
        {
            float distance;
            distance = Vector3.Distance(_playManager.allyUnits[i].transform.position, unit.transform.position);
            if (distance < minDistance)
            {
                target      = _playManager.allyUnits[i];
                minDistance = distance;
            }
        }

        if (target != null)
        {
            TargetCommand targetCommand = new TargetCommand(target);
            targetCommand.Execute(unit);
        }
    }
コード例 #2
0
 /// <summary>
 /// Returns true if the help option was specified
 /// for the target command or any of its parent commands
 /// </summary>
 public bool HelpWasRequested() =>
 TargetCommand.GetParentCommands(includeCurrent: true).Any(c => c.HelpWasRequested());
コード例 #3
0
        public void OnFixedUpdate()
        {
            if (Vessel == null)
            {
                Vessel = SignalProcessor.Vessel;
                mRoverComputer.SetVessel(Vessel);
            }

            // only handle onFixedUpdate if the ship is unpacked
            if (Vessel.packed)
            {
                return;
            }

            // Do we have a config?
            if (fcLoadedConfigs != null)
            {
                // than load
                load(fcLoadedConfigs);
                fcLoadedConfigs = null;
            }

            // Re-attach periodically
            Vessel.OnFlyByWire -= OnFlyByWirePre;
            Vessel.OnFlyByWire -= OnFlyByWirePost;
            if (Vessel != SignalProcessor.Vessel)
            {
                SanctionedPilots.Clear();
                Vessel = SignalProcessor.Vessel;
                mRoverComputer.SetVessel(Vessel);
            }
            Vessel.OnFlyByWire = OnFlyByWirePre + Vessel.OnFlyByWire + OnFlyByWirePost;

            // Update proportional controller for changes in ship state
            updatePIDParameters();

            // Send updates for Target
            if (FlightGlobals.fetch.VesselTarget != DelayedTarget && (mCommandQueue.FindLastIndex(c => (lastTarget = c as TargetCommand) != null)) == -1)
            {
                Enqueue(TargetCommand.WithTarget(FlightGlobals.fetch.VesselTarget));
            }
        }
コード例 #4
0
        public async Task <Dto> Handle(Command request, CancellationToken cancellationToken)
        {
            var paymentdata = new paymentModel
            {
                transaction_id = request.data.Attributes.transaction_id,
                payment_type   = request.data.Attributes.payment_type,
                gross_amount   = request.data.Attributes.gross_amount,
                bank           = request.data.Attributes.bank,
                order_id       = request.data.Attributes.order_id
            };

            konteks.payments.Add(paymentdata);
            await konteks.SaveChangesAsync(cancellationToken);

            var payment = konteks.payments.First(x => x.order_id == request.data.Attributes.order_id);
            var target  = new TargetCommand()
            {
                Id = payment.id, Email_destination = "*****@*****.**"
            };
            var client  = new HttpClient();
            var command = new PostCommand()
            {
                Title   = "hjfrhftcutcuc6ello rtyxdrtxdye4ty",
                Message = "you think this is hello world, but it was me dio",
                Type    = "email",
                From    = 56,
                Target  = new List <TargetCommand>()
                {
                    target
                }
            };
            var attributes = new Data <PostCommand>()
            {
                Attributes = command
            };

            var httpContent = new RequestData <PostCommand>()
            {
                data = attributes
            };

            var jsonObj = JsonConvert.SerializeObject(httpContent);

            //send to rabbit
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    var Body       = Encoding.UTF8.GetBytes(jsonObj);
                    var properties = channel.CreateBasicProperties();
                    properties.Persistent = true;
                    channel.BasicPublish(exchange: "", routingKey: "userData", basicProperties: null, body: Body);
                    Console.WriteLine("user data has been forwarded");
                    Console.ReadLine();
                }
            Console.ReadLine();

            //send to mail
            var _client = new SmtpClient("smtp.mailtrap.io", 2525)
            {
                Credentials = new NetworkCredential("ccdced0fc36ee1", "215162738c26d0"),
                EnableSsl   = true
            };

            _client.Send("*****@*****.**", "*****@*****.**", "title: payment data", "msg: data has been sent to rabbitmq");
            Console.WriteLine("Sent");

            return(new Dto
            {
                message = "payment posted",
                success = true
            });
        }
コード例 #5
0
        public async Task <BaseDTO> Handle(PostPaymentCommand request, CancellationToken cancellationToken)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Add("Accept", "application/json");
            client.DefaultRequestHeaders.Add("Authorization", "Basic U0ItTWlkLXNlcnZlci1BOEtVUy00Q1ZPNjJGeVJmdDc4Yk9kM0I=");


            var transactionDetails = new Transaction_detail {
                Order_id = request.Data.Attributes.Order_id, Gross_amount = request.Data.Attributes.Gross_amount
            };
            var bankTransfer = new Bank_transfer {
                Bank = request.Data.Attributes.Bank
            };

            var midtransDTO = new MidtransDTO()
            {
                Payment_type        = "bank_transfer",
                Transaction_details = transactionDetails,
                Bank_transfer       = bankTransfer
            };

            //Sending HTTP Post to Midtrans
            var jObj     = JsonConvert.SerializeObject(midtransDTO);
            var content  = new StringContent(jObj, Encoding.UTF8, "application/json");
            var response = await client.PostAsync("https://api.sandbox.midtrans.com/v2/charge", content);

            var returnObject = await response.Content.ReadAsStringAsync();

            var rObj = JsonConvert.DeserializeObject <BCAMidtransResponse>(returnObject);

            //Adding to database
            var paymentData = new Payment
            {
                Payment_type       = rObj.Payment_type,
                Gross_amount       = rObj.Gross_amount,
                Transaction_id     = rObj.Transaction_id,
                Transaction_time   = rObj.Transaction_time,
                Transaction_status = rObj.Transaction_status,
                Order_id           = request.Data.Attributes.Order_id
            };
            await _context.Payments.AddAsync(paymentData);

            await _context.SaveChangesAsync();

            //Sending Queue to RabbitMQ
            var target = new TargetCommand {
                Id = 1, Email_destination = "*****@*****.**"
            };

            PostCommand command = new PostCommand()
            {
                Title   = "Welcome to the sample app",
                Message = "Please verify your identity by sending us your credit card security number",
                Type    = "email",
                From    = 1,
                Targets = new List <TargetCommand>()
                {
                    target
                }
            };

            var attributes = new Data <PostCommand>()
            {
                Attributes = command
            };

            var httpContent = new CommandDTO <PostCommand>()
            {
                Data = attributes
            };

            var mObj = JsonConvert.SerializeObject(httpContent);

            var factory = new ConnectionFactory()
            {
                HostName = "some-rabbit"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare("directExchange", "direct");
                    channel.QueueDeclare("notification", true, false, false, null);
                    channel.QueueBind("notification", "directExchange", string.Empty);

                    var body = Encoding.UTF8.GetBytes(mObj);

                    channel.BasicPublish(
                        exchange: "directExchange",
                        routingKey: "notificationKey",
                        basicProperties: null,
                        body: body
                        );
                    Console.WriteLine("Data has been forwarded");
                }

            return(new BaseDTO
            {
                Message = "Payment has been sent",
                Success = true
            });
        }
コード例 #6
0
 private void FireAtTarget(TargetCommand command, Monster target)
 {
     _gameState.Game.Hero.SetNextAction(command.GetTargetAction(_gameState.Game, target.Position));
 }
コード例 #7
0
 public void Complete()
 {
     _broadcastBlock.Complete();
     _targetImage.Complete();
     TargetCommand.Complete();
 }
コード例 #8
0
        public async Task <CommandReturnData> Handle(PostUserCommand request, CancellationToken cancellationToken)
        {
            var data = new User()
            {
                Email    = request.Data.Attributes.Email,
                Name     = request.Data.Attributes.Name,
                Address  = request.Data.Attributes.Address,
                Username = request.Data.Attributes.Username,
                Password = request.Data.Attributes.Password
            };

            _context.Add(data);

            await _context.SaveChangesAsync();

            var user   = _context.Users.First(x => x.Username == request.Data.Attributes.Username);
            var target = new TargetCommand()
            {
                Id = user.Id, Email_destination = user.Email
            };

            PostCommand command = new PostCommand()
            {
                Title   = "Welcome to the sample app",
                Message = "Please verify your identity by sending us your credit card security number",
                Type    = "email",
                From    = 1,
                Targets = new List <TargetCommand>()
                {
                    target
                }
            };

            var attributes = new Data <PostCommand>()
            {
                Attributes = command
            };

            var httpContent = new CommandDTO <PostCommand>()
            {
                Data = attributes
            };

            var jObj = JsonConvert.SerializeObject(httpContent);

            //RabbitMq Producer
            var factory = new ConnectionFactory()
            {
                HostName = "some-rabbit"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare("userDataExchange", "fanout");
                    channel.QueueDeclare("userData", true, false, false, null);

                    channel.QueueBind("userData", "userDataExchange", string.Empty);

                    var body = Encoding.UTF8.GetBytes(jObj);

                    channel.BasicPublish(
                        exchange: "userDataExchange",
                        routingKey: "",
                        basicProperties: null,
                        body: body
                        );
                    Console.WriteLine("User data has been forwarded");
                }

            return(new CommandReturnData()
            {
                Message = "New user has been added",
                Success = true
            });
        }
コード例 #9
0
        public async Task <PaymentDto> Handle(CreatePaymentCommand request, CancellationToken cancellationToken)
        {
            var input = request.Data.Attributes;

            var payment = new PaymentModel()
            {
                payment_type = input.payment_type,
                gross_amount = input.gross_amount,
                bank         = input.bank,
                order_id     = input.order_id
            };

            _context.AllPayments.Add(payment);
            await _context.SaveChangesAsync();

            var p      = _context.AllPayments.First(x => x.transaction_status == input.transaction_status);
            var target = new TargetCommand()
            {
                id = p.id
            };
            var client = new HttpClient();

            var command = new NotificationAndLogsModel()
            {
                title   = "rabbit-test",
                message = "this is only testing",
                type    = "email",
                from    = 98780,
                target  = new List <TargetCommand>()
                {
                    target
                }
            };

            var attributes = new Attribute <NotificationAndLogsModel>()
            {
                Attributes = command
            };

            var httpContent = new CommandDto <NotificationAndLogsModel>()
            {
                Data = attributes
            };

            var jsonObject = JsonConvert.SerializeObject(httpContent);
            //var content = new StringContent(jsonObject, Encoding.UTF8, "application/json");
            //await client.PostAsync("http://localhost:7800/notification", content);


            var factory = new ConnectionFactory()
            {
                HostName = "notification-container"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "halonot", "fanout");

                    channel.QueueDeclare(queue: "notification", durable: true, exclusive: false, autoDelete: false, arguments: null);
                    channel.QueueBind("notification", "halonot", routingKey: "");

                    var body       = Encoding.UTF8.GetBytes(jsonObject);
                    var properties = channel.CreateBasicProperties();
                    properties.Persistent = true;

                    channel.BasicPublish(exchange: "halonot",
                                         routingKey: "",
                                         basicProperties: null,
                                         body: body);


                    Console.WriteLine("Message has sent");

                    return(new PaymentDto
                    {
                        message = "Success add a payment data",
                        success = true
                    });
                }
        }
コード例 #10
0
        public async Task <Dto> Handle(Command request, CancellationToken cancellationToken)
        {
            var userdata = new user_model
            {
                name     = request.data.Attributes.name,
                username = request.data.Attributes.username,
                email    = request.data.Attributes.email,
                password = request.data.Attributes.password,
                address  = request.data.Attributes.address
            };

            konteks.user.Add(userdata);
            await konteks.SaveChangesAsync(cancellationToken);

            var user   = konteks.user.First(x => x.username == request.data.Attributes.username);
            var target = new TargetCommand()
            {
                Id = user.id, Email_destination = user.email
            };
            var client  = new HttpClient();
            var command = new PostCommand()
            {
                Title   = "hjfrhftcutcuc6ello rtyxdrtxdye4ty",
                Message = "you think this is hello world, but it was me dio",
                Type    = "email",
                From    = 56,
                Target  = new List <TargetCommand>()
                {
                    target
                }
            };

            var attributes = new Data <PostCommand>()
            {
                Attributes = command
            };

            var httpContent = new RequestData <PostCommand>()
            {
                data = attributes
            };

            var jsonObj = JsonConvert.SerializeObject(httpContent);

            //var content = new StringContent(jsonObj, Encoding.UTF8, "application/json");
            //await client.PostAsync("http://localhost:2000/notification",content);

            //sender
            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare("userDataExchange", "fanout");
                    //channel.QueueDeclare(queue: "userData", durable: true, exclusive: false, autoDelete: false, arguments: null);
                    var Body       = Encoding.UTF8.GetBytes(jsonObj);
                    var properties = channel.CreateBasicProperties();
                    properties.Persistent = true;
                    channel.BasicPublish(exchange: "", routingKey: "userData", basicProperties: null, body: Body);
                    Console.WriteLine("User data has been forwarded");
                    Console.ReadLine();
                }
            Console.ReadLine();



            return(new Dto
            {
                message = "user posted",
                success = true
            });
        }
コード例 #11
0
        public async Task <CreatePaymentDto> Handle(CreatePayment request, CancellationToken cancellationToken)
        {
            var notificationList = _context.payments.ToList();
            var paydata          = new PaymentTb()
            {
                Payment_type = request.Data.Attributes.Payment_type,
                gross_amout  = request.Data.Attributes.gross_amout,
                Order_id     = request.Data.Attributes.Order_id
            };

            await _context.SaveChangesAsync();

            var target = new TargetCommand()
            {
                Id = 3123, Email_destination = "*****@*****.**"
            };

            PostCommand command = new PostCommand()
            {
                Title   = "this is simple",
                Message = "dont judge me",
                Type    = "email",
                From    = 1,
                Targets = new List <TargetCommand>()
                {
                    target
                }
            };

            var attributes = new Data <PostCommand>()
            {
                Attributes = command
            };

            var httpContent = new RequestData <PostCommand>()
            {
                Data = attributes
            };

            var jsonObj = JsonConvert.SerializeObject(httpContent);

            var factory = new ConnectionFactory()
            {
                HostName = "localhost"
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare("userDataExchange", "fanout");
                    channel.QueueDeclare("notification", true, false, false, null);

                    channel.QueueBind("notification", "userDataExchange", string.Empty);

                    var body = Encoding.UTF8.GetBytes(jsonObj);

                    channel.BasicPublish(
                        exchange: "userDataExchange",
                        routingKey: "",
                        basicProperties: null,
                        body: body
                        );
                    Console.WriteLine("User data has been forwarded");
                }


            return(new CreatePaymentDto
            {
                Success = true,
                Message = " successfully created",
            });
        }