Exemplo n.º 1
0
    void OnConnectNewClient(RegisterPackage package, EndPoint endPoint)
    {
        try {
            nextClient.tankID   = package.tankID;
            nextClient.endPoint = endPoint;
            networkInterface.SendTo(new RegisterPackage()
            {
                playerID    = nextClient.playerID,
                packageType = NetworkDataType.Register
            }, endPoint);

            foreach (var client in clients)
            {
                UploadTankTo(client, nextClient);
                UploadTankTo(nextClient, client);
            }
            clients.Add(nextClient);
            nextClient = new ClientInfo()
            {
                playerID = freePlayerID++
            };
        }
        catch (Exception e) {
            Debug.Log(e);
            Debug.Log(e.StackTrace);
            Debug.Log(e.Message);
        }
    }
Exemplo n.º 2
0
        public async Task <IActionResult> PutAsync(string packageId, [FromBody] RegisterPackage command)
        {
            if (ModelState.IsValid)
            {
                var package = await _packageRepo.GetPackageAsync(packageId);

                if (package != null)
                {
                    // Shipping Checklist for package and transport
                    bool packageIsIssued    = false;
                    bool transportIsChecked = false;
                    var  transports         = await _transportRepo.GetTransportsAsync(package.PackageId);

                    var transport = await _transportRepo.GetTransportAsync(command.Transport.TransportId);

                    // Update Package
                    // (NOTE: Only "ShippingStatus", "BarcodeNumber", "Delivered" and "Transport")
                    package.BarcodeNumber = command.BarcodeNumber;

                    // Check if "ShippingStatus" is "IN STOCK" and transport choice is not null
                    if (package.ShippingStatus == "IN STOCK" && command.Transport != null)
                    {
                        // (NOTE: If transport choice is in the available list of transports update the package
                        if (transports.Count() != 0 && transport != null && transports.Any(t => t == transport))
                        {
                            package.ShippingStatus = "ISSUE";
                            package.Delivered      = false;
                            package.Transport      = transport;

                            packageIsIssued    = true;
                            transportIsChecked = true;
                        }
                        else
                        {
                            return(NotFound());
                        }
                    }

                    await _packageRepo.UpdatePackageAsync();

                    if (packageIsIssued == true && transportIsChecked == true)
                    {
                        // Send Event
                        RegisterPackage   c = Mapper.Map <RegisterPackage>(package);
                        PackageRegistered e = Mapper.Map <PackageRegistered>(c);
                        await _messagePublisher.PublishMessageAsync(e.MessageType, e, "");

                        return(CreatedAtRoute("GetPackageById", new { packageId = package.PackageId }, package));
                    }
                }

                return(NotFound());
            }

            return(BadRequest());
        }
Exemplo n.º 3
0
        public bool Register(RegisterPackage package)
        {
            if (null != package.Phone && "" != package.Phone)
            {
                string sql_checkphone = "select * from " +
                                        DBStaticData.DataBaseUserTableName +
                                        " where " +
                                        DBStaticData.DataBaseUserTablePhoneField + " = '" + package.Phone + "'";
                if (ExecuteNonDataSet(sql_checkphone, out DataSet set))
                {
                    if (0 != set.Tables.Count)
                    {
                        if (0 != set.Tables[0].Rows.Count)
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    return(false);
                }
            }
            string token = DBStaticMethod.GetToken();
            string sql   = string.Format
                           (
                "insert into {0} values ('{1}', '{2}', '{3}', '{4}', '{5}', '{6}', '{7}', {8})",
                DBStaticData.DataBaseUserTableName,
                package.ID,
                DBStaticMethod.SHA256(package.Password, token),
                token,
                package.Name,
                package.Email,
                package.Phone,
                package.Describe,
                package.Photo.ToString()
                           );

            if (!ExecuteNonQuery(sql))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 4
0
 private void NetworkEventMaster_OnRegisterPackage(RegisterPackage package, EndPoint endPoint)
 {
     localPlayerID = package.playerID;
 }
Exemplo n.º 5
0
    private void NetworkEventMaster_OnNewTank(RegisterPackage package)
    {
        GameObject newTank = Instantiate(tankPrefubManager.prefubs[package.tankID]);

        networkPlayers[package.playerID] = newTank.GetComponent <CaterpillarController>();
    }
Exemplo n.º 6
0
        public async Task <IActionResult> PostAsync([FromBody] RegisterPackage command)
        {
            if (ModelState.IsValid)
            {
                Package package = Mapper.Map <Package>(command);

                // Checklist for package, order and product
                List <Product> products         = new List <Product>();
                List <Order>   orders           = new List <Order>();
                bool           packageIsChecked = false;
                bool           orderIsChecked   = false;

                foreach (var order in package.Orders)
                {
                    // Get the order from order repository
                    var ord = await _orderRepo.GetOrderAsync(order.OrderId);

                    if (ord != null)
                    {
                        // Create a "PackageOrder" entity and map the relationships with package and order
                        var packageOrder = new PackageOrder
                        {
                            Package = package,
                            Order   = ord,
                        };

                        // Add both "PackageOrder" and "Order" to the package
                        package.PackageOrders.Add(packageOrder);
                        orders.Add(ord);
                    }
                    else
                    {
                        return(NotFound());
                    }
                }

                // Check if ALL the orders have the same value in order "Destination"
                // (NOTE: Orders must have the same destination in order to be packaged)
                if (orders.Count != 0)
                {
                    orderIsChecked = !package.Orders
                                     .Select(o => o.Destination)
                                     .Distinct()
                                     .Skip(1)
                                     .Any();
                }
                else
                {
                    return(BadRequest());
                }

                foreach (var product in package.Products)
                {
                    // Get the product from product repository
                    var prod = await _productRepo.GetProductAsync(product.ProductId);

                    if (prod != null)
                    {
                        // Add the total weight to the package from all products
                        package.WeightInKgMax += prod.Weight;

                        // Create a "PackageProduct" entity and map the relationships with package and product
                        var packageProduct = new PackageProduct
                        {
                            Package = package,
                            Product = prod,
                        };

                        // Add both "PackageProduct" and "Product" to the package
                        package.PackageProducts.Add(packageProduct);
                        products.Add(prod);
                    }
                    else
                    {
                        return(NotFound());
                    }
                }

                // Replace the current package "Orders" and "Products" with correct ones
                if (orders.Count != 0 && products.Count != 0)
                {
                    package.Orders   = orders;
                    package.Products = products;
                }

                // Check if the package is of the type "Letterbox" and its total weight is less or equal to 2
                // (NOTE: This is a "Letterbox" package)
                if (package.TypeOfPackage == "Letterbox package" && package.WeightInKgMax <= 2)
                {
                    packageIsChecked = true;
                }

                // Check if the package is NOT of type "Letterbox" and its total weight is greater then 2 and less or equal to 20
                // (NOTE: This is a "Package" of any kind)
                if (package.TypeOfPackage != "Letterbox package" && package.WeightInKgMax > 2 && package.WeightInKgMax <= 20)
                {
                    packageIsChecked = true;
                }

                if (packageIsChecked == true && orderIsChecked == true)
                {
                    // Insert Package
                    package.Region         = package.Orders.Select(o => o.Destination).FirstOrDefault();
                    package.ShippingStatus = "IN STOCK";
                    package.Transport      = null;
                    await _packageRepo.AddPackageAsync(package);

                    return(CreatedAtRoute("GetPackageById", new { packageId = package.PackageId }, package));
                }

                return(BadRequest());
            }

            return(BadRequest());
        }
Exemplo n.º 7
0
        public void Register(string username, string password)
        {
            TcpClient = new TcpClient();

            if (TcpClient != null && !TcpClient.Connected)
            {
                Connect(Settings.Default.IP, Settings.Default.Port);
            }

            RegisterPackage registerPackage = new RegisterPackage()
            {
                Password = password,
                Username = username
            };
            if (TcpClient.Connected)
            {
                _binaryFormatter.Serialize(TcpClient.GetStream(), registerPackage);

                object receivedObject = _binaryFormatter.Deserialize(TcpClient.GetStream());

                if (receivedObject.GetType() == typeof(RegisterResponsePackage))
                {
                    RegisterResponsePackage registerResponsePackage = receivedObject as RegisterResponsePackage;

                    if (registerResponsePackage.Success)
                        MainWindow.PrintStatus("Registered successfully!");
                    else
                        MainWindow.PrintStatus("Registration failed!");
                }
            }
            TcpClient.Close();
        }