Beispiel #1
0
        public User GetUser(string id)
        {
            //Get player,player skills and player stats
            var user = new StoredUser().GetUser(id);

            return(user);
        }
Beispiel #2
0
        public override void Deserialize(NetworkReader reader)
        {
            BinaryFormatter bf = new BinaryFormatter();
            MemoryStream    ms = new MemoryStream(reader.ReadBytesAndSize());

            User = (StoredUser)bf.Deserialize(ms);
            ms.Dispose();
        }
Beispiel #3
0
    public void ValidateForm()
    {
        if (_userForm.transform.Find("UserName").Find("Text").gameObject.GetComponent <Text>().text != "")
        {
            // Save to DB
//            _userCode = _userForm.transform.Find("UserName").Find("Text").gameObject.GetComponent<Text>().text;
            StoredUser user = new StoredUser(_userForm.transform.Find("UserName").Find("Text").gameObject.GetComponent <Text>().text, Helpers.ParseQuestionarie(_userForm));
            MyNetworkManager.singleton.client.Send(MyMsgType.NewUserData, new StoredUserMessage(user));
            Destroy(_userForm);
        }
        else
        {
            // Do nothing
            return;
        }
    }
Beispiel #4
0
        /// <summary>
        /// Adds the current context user to a Room.
        /// </summary>
        /// <param name="HashSumUser">Hash SHA user.</param>
        /// <param name="userName">Display Name.</param>
        /// <param name="ChatRoom">Chatroom to join.</param>
        /// <returns>UserInfoBase of the user.</returns>
        private async Task <UserInfoBase> AddUsertoRoomAsync(string HashSumUser, string userName, string ChatRoom)
        {
            UserInformation currentUserInfo = null;

            if (SavedUserInfo.HasData(HashSumUser))
            {
                StoredUser userInFile = SavedUserInfo.GetStoredUser(HashSumUser);
                currentUserInfo = new UserInformation(Context.ConnectionId, userInFile.DisplayName, RandomNumberThread.Instance.Next(LowNumber, MaxNumber).ToString(), true);
            }
            else
            {
                currentUserInfo = new UserInformation(Context.ConnectionId, userName, RandomNumberThread.Instance.Next(LowNumber, MaxNumber).ToString(), false);
            }
            RoomToUsers[ChatRoom].Add(currentUserInfo);
            await Groups.AddToGroupAsync(Context.ConnectionId, ChatRoom);

            return(currentUserInfo);
        }
Beispiel #5
0
 private async Task AddExampleOrder(StoredUser user, Product product)
 {
     if (!await _context.Orders.AnyAsync(o => o.Id == 1))
     {
         await _context.Orders.AddAsync(new Order
         {
             User        = user,
             OrderDate   = new DateTime(),
             OrderNumber = "1",
             Items       = new List <OrderItem>()
             {
                 new OrderItem {
                     Product   = product,
                     Quantity  = 5,
                     UnitPrice = product.Price
                 }
             }
         });
     }
 }
Beispiel #6
0
        public StoredUser GetUser(string username, string password)
        {
            StoredUser user = null;

            try
            {
                using (SqlConnection conn = new SqlConnection(databaseConnectionString))
                {
                    SqlCommand cmd = new SqlCommand("GetUser", conn);
                    cmd.CommandType = System.Data.CommandType.StoredProcedure;

                    conn.Open();

                    cmd.Parameters.AddWithValue("@username", username);
                    cmd.Parameters.AddWithValue("@password", password);


                    var result = cmd.ExecuteReader();

                    while (result.Read())
                    {
                        user = new StoredUser
                        {
                            UserName = Convert.ToString(result["UserName"]),
                            Password = Convert.ToString(result["Password"]),
                            Email    = Convert.ToString(result["Email"]),
                            Gender   = Convert.ToString(result["Gender"]),
                            Faction  = Convert.ToString(result["Faction"]),
                            Class    = Convert.ToString(result["Class"]),
                            Race     = Convert.ToString(result["Race"])
                        };
                    }
                }
            }
            catch (SqlException ex)
            {
                throw ex;
            }
            return(user);
        }
Beispiel #7
0
        public async Task Seed()
        {
            await _context.Database.EnsureCreatedAsync();

            StoredUser user = await _userManager.FindByEmailAsync(_configuration["Defaults:User:Email"]);

            if (user == null)
            {
                user = new StoredUser
                {
                    FirtsName = _configuration["Defaults:User:Name"],
                    LastName  = _configuration["Defaults:User:LastName"],
                    Email     = _configuration["Defaults:User:Email"],
                    UserName  = _configuration["Defaults:User:Email"]
                };

                var result = await _userManager.CreateAsync(user, _configuration["Defaults:User:Password"]);

                if (result != IdentityResult.Success)
                {
                    throw new InvalidOperationException("Could not create new user in seeder");
                }
            }

            if (_context.Products.Any())
            {
                return;
            }

            var products = await ListExampleProducts();

            await _context
            .Products
            .AddRangeAsync(products);

            await AddExampleOrder(user, products.FirstOrDefault());

            await _context.SaveChangesAsync();
        }
Beispiel #8
0
 public StoredUserMessage(StoredUser user)
 {
     User = user;
 }
    public void AddUser(NetworkMessage message)
    {
        StoredUserMessage msg  = message.ReadMessage <StoredUserMessage>();
        StoredUser        user = msg.User;

        user.TestGroup = _config.TestGroup;
        //Generate random code:
        string code;
        var    resultDb = MongoDBConnector.GetInstance().GetResultsDatabase();
        var    registeredUsersCollection = resultDb.GetCollection <BsonDocument>("Users");
        int    count;

        do
        {
            code  = GenRandomCode();
            count = registeredUsersCollection.Find(new BsonDocument {
                { "_id", code }
            }).Limit(1).ToList().Count;
        } while (count != 0);
        user.Code = code;
        var db         = MongoDBConnector.GetInstance().GetDatabase();
        var collection = db.GetCollection <BsonDocument>("Users");
        var document   = new BsonDocument
        {
            { "Name", user.Name },
            { "TestGroup", user.TestGroup },
            { "Code", user.Code },
            { "Questionarie", new BsonDocument {
                  { "AgeGroup", user.Results.AgeGroup },
                  { "TouchFrequency", user.Results.TouchFrequency },
                  { "None", user.Results.None },
                  { "Smaller5", user.Results.Smaller5 },
                  { "Smaller11", user.Results.Smaller11 },
                  { "Greater11", user.Results.Greater11 },
                  { "Activities", user.Results.Activities },
                  { "ColorPerception", user.Results.ColorPerception }
              } }
        };

        collection.InsertOne(document);
        var devices = (user.Results.None.ToInt() << 3) +
                      (user.Results.Smaller5.ToInt() << 2) +
                      (user.Results.Smaller11.ToInt() << 1) +
                      user.Results.Greater11.ToInt();

        document = new BsonDocument
        {
            { "_id", code },
            { "AgeGroup", user.Results.AgeGroup },
            { "ColorPerception", user.Results.ColorPerception },
            { "TouchFrequency", user.Results.TouchFrequency },
            { "Activities", user.Results.Activities },
            { "Devices", devices }
        };
        registeredUsersCollection.InsertOne(document);
        var filter = Builders <BsonDocument> .Filter.Eq("_id", "UserCount");

        var update = Builders <BsonDocument> .Update.Inc("Count", 1);

        resultDb.GetCollection <BsonDocument>("counters").FindOneAndUpdate(filter, update);
    }