Example #1
0
        private void AddMailboxToDumpDb(MailboxData mailboxData)
        {
            if (!_tasksConfig.UseDump)
            {
                return;
            }

            try
            {
                lock (_locker)
                {
                    var mailbox = _mailboxes.FindOne(Query.EQ("MailboxId", mailboxData.MailboxId));

                    if (mailbox != null)
                    {
                        return;
                    }

                    _mailboxes.Insert(mailboxData);

                    // Create, if not exists, new index on Name field
                    _mailboxes.EnsureIndex(x => x.MailboxId);
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("AddMailboxToDumpDb(id={0}) Exception: {1}", mailboxData.MailboxId, ex.ToString());

                ReCreateDump();
            }
        }
Example #2
0
        private static void removePlayer()
        {
            string name = "";

            Console.Write("\nName of player to remove: ");
            name = Console.ReadLine();
            if (userLoginColl.FindOne(x => x.username == name) == null)
            {
                Console.WriteLine("Could not find any player named \"" + name);
                return;
            }

            Console.WriteLine("Are you sure you wish to remove \"" + name + "\"? (y/n) ");
            if (Console.ReadLine().ToLower() == "y")
            {
                userLoginColl.Delete(name);
                Console.WriteLine("Succesfully removed login credentials for: \"" + name + "\"");

                if (userGameStatColl.FindOne(x => x.username == name) != null)
                {
                    userGameStatColl.Delete(name);
                    Console.WriteLine("Succesfully removed game data for: \"" + name + "\"");
                }
                else
                {
                    Console.WriteLine("Could not find and remove game data for: \"" + name + "\"");
                }
            }
        }
Example #3
0
        public void FindLocker_Test()
        {
            Assert.AreEqual(col.Count(), 0);

            // insert data
            Task.Factory.StartNew(InsertData).Wait();

            // test inserted data :: Info = 1
            var data = col.FindOne(o => o.Key == "Test1");

            Assert.IsNotNull(data);
            Assert.AreEqual(1, data.Info);

            // update data :: Info = 77
            Task.Factory.StartNew(UpdateData).Wait();

            // find updated data
            data = col.FindOne(o => o.Key == "Test1");
            Assert.IsNotNull(data);
            Assert.AreEqual(77, data.Info);

            // drop collection
            db.DropCollection("col1");
            Assert.AreEqual(db.CollectionExists("col1"), false);
        }
        public void UpdatePorts(string entityid)
        {
            var services = Enum.GetValues(typeof(Service)).Cast <int>().ToArray();
            var entity   = GetEntity(entityid);

            if (entity == null)
            {
                return;
            }
            if (entity.IsNPC)
            {
                return;
            }
            foreach (var service in services)
            {
                if (_protectedPorts.FindOne(x => x.EntityId == entityid && x.Port == service) == null)
                {
                    _protectedPorts.Insert(new ProtectedPort
                    {
                        Id            = Guid.NewGuid().ToString(),
                        EntityId      = entityid,
                        Port          = (ushort)service,
                        SecurityLevel = 1
                    });
                    Plex.Objects.Logger.Log($"Enabled service {service} with security level 1 on {entityid}.");
                }
            }
        }
Example #5
0
        public Task <TRole> FindByIdAsync(string roleId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            return(Task.FromResult(_roles.FindOne(u => u.Id == roleId)));
        }
Example #6
0
        private void AddTenantToDumpDb(TenantData tenantData)
        {
            if (!_tasksConfig.UseDump)
            {
                return;
            }

            try
            {
                lock (_locker)
                {
                    var tenant = _tenants.FindOne(Query.EQ("Tenant", tenantData.Tenant));

                    if (tenant != null)
                    {
                        return;
                    }

                    _tenants.Insert(tenantData);

                    // Create, if not exists, new index on Name field
                    _tenants.EnsureIndex(x => x.Tenant);
                }
            }
            catch (Exception ex)
            {
                _log.ErrorFormat("AddTenantToDumpDb(tenantId={0}) Exception: {1}", tenantData.Tenant, ex.ToString());

                ReCreateDump();
            }
        }
Example #7
0
        private Dictionary <string, object> GetEmployee()
        {
            string   name     = (string)_requestDictionary["name"];
            Employee employee = _employeeCol.FindOne(x => x.Name.Equals(name));
            Dictionary <string, object> employeeDict = employee.EmployeeToDictionary();

            return(employeeDict);
        }
Example #8
0
        public async Task <Client> GetClientByApiKey(string apiKey)
        {
            var c = await Task.Run(() => {
                return(clients.FindOne(client => client.ApiKey == apiKey));
            });

            return(c);
        }
Example #9
0
        public TransactionBlock FindLatestBlock(string AccountId)
        {
            var count = GetBlockCount(AccountId);
            //var result = _blocks.FindOne(x => x.Index.Equals(count));
            var result = _blocks.FindOne(x => x.AccountID == AccountId && x.Index.Equals(count));

            return((TransactionBlock)result);
        }
        public Task <TUser> FindByIdAsync(string userId, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            cancellationToken.ThrowIfCancellationRequested();
            return(Task.FromResult(_users.FindOne(u => u.Id == userId)));
        }
Example #11
0
        public TransactionModel.Get Fetch(int id)
        {
            var transaction = transactions
                              .FindOne(t => t.Id == id);

            Ensure.This(transaction).CompliesWith(t => t != null, $"Cannot find transaction with id '{id}'");

            return(new TransactionModel.Get(transaction));
        }
Example #12
0
 public static void ChangePassword(string username, string oldPass, string newPass)
 {
     if (AttemptLogin(username, oldPass))
     {
         UserEntry userEntry = users.FindOne(x => x.username == username);
         userEntry.saltHashCombo = Hasher.EncryptPassword(newPass);
         users.Update(userEntry);
     }
 }
        public string GetPlayerId(string entityid)
        {
            var player = _players.FindOne(x => x.EntityId == entityid);

            if (player == null)
            {
                return(null);
            }
            return(player.ItchUserId);
        }
        public Stat GetPreviousDayStat()
        {
            var previousDay = DateTime.UtcNow.Date.AddSeconds(-1);

            var dailyStatId = GetDailyStatId(previousDay);

            var dailyStat = _stats.FindOne(x => x.Id == dailyStatId);

            return(dailyStat);
        }
        public string GetAddress(string entity)
        {
            var address = _addresses.FindOne(x => x.Entity == entity);

            if (address != null)
            {
                return(address.Name + "@serenitymail.net");
            }
            return(null);
        }
Example #16
0
        public TokenGenesisBlock FindTokenGenesisBlock(string Hash, string Ticker)
        {
            //TokenGenesisBlock result = null;
            if (!string.IsNullOrEmpty(Hash))
            {
                var result = _blocks.FindOne(Query.EQ("Hash", Hash));
                if (result != null)
                {
                    return(result as TokenGenesisBlock);
                }
            }

            // to do - try to replace this by indexed search using BlockType indexed field (since we can't index Ticker field):
            // find all GenesysBlocks first, then check if one of them has the right ticker
            if (!string.IsNullOrEmpty(Ticker))
            {
                var result = _blocks.FindOne(Query.EQ("Ticker", Ticker));
                if (result != null)
                {
                    return(result as TokenGenesisBlock);
                }
            }

            return(null);
        }
Example #17
0
 public static Classes.Server GetServerInfo(LiteCollection <Classes.Server> serversCollection, string endpoint)
 {
     if (!(serversCollection.FindOne(x => x.Endpoint == endpoint) == null))
     {
         return(serversCollection.FindOne(x => x.Endpoint == endpoint));
     }
     else
     {
         throw new WebFaultException(System.Net.HttpStatusCode.NotFound);
     }
 }
 public static Match GetMatchInfo(LiteCollection <Match> matchesCollection, string endpoint, string timestamp)
 {
     if (!(matchesCollection.FindOne(x => x.Endpoint == endpoint && x.StringTimestamp == timestamp) == null))
     {
         return(matchesCollection.FindOne(x => x.Endpoint == endpoint && x.StringTimestamp == timestamp));
     }
     else
     {
         throw new WebFaultException(System.Net.HttpStatusCode.NotFound);
     }
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="SessionID"></param>
 /// <param name="UserID"></param>
 /// <returns></returns>
 /// <exception cref="ArgumentException"/>
 public User FindOneUser(Guid SessionID, int UserID)
 {
     if (SessionID != null && SessionID != newGuid && UserID > 0)
     {
         return(dataBaseCollection.FindOne(x => x.Id == UserID && x.SessionID == SessionID));
     }
     else
     {
         throw new ArgumentException("SessionID is null or empty(00000..) or UserID < 1", "SessionID || UserID");
     }
 }
Example #20
0
        //Should later be rewritten so we separate a update and a new entry. For opting the performance
        //Also use Generics/Polymorphism
        #region Setters
        public static void updateLoginInfo(UserLoginInformation update)
        {
            UserLoginInformation loginAttempt = userLoginColl.FindOne(x => x.username == update.username);

            if (loginAttempt == null)
            {
                userLoginColl.Insert(update);
            }
            else
            {
                userLoginColl.Update(update);
            }
        }
Example #21
0
 public static void AddServerInfo(LiteCollection <Classes.Server> serversCollection, Classes.Server server, string endpoint)
 {
     server.Endpoint = endpoint;
     if (serversCollection.FindOne(x => x.Endpoint == endpoint) == null)
     {
         serversCollection.Insert(server);
     }
     else
     {
         server.Id = serversCollection.FindOne(x => x.Endpoint == endpoint).Id;
         serversCollection.Update(server);
     }
 }
Example #22
0
        public static void updateChatLog(UserChatLog update)
        {
            UserChatLog loginAttempt = userChatLogColl.FindOne(x => x.username == update.username);

            if (loginAttempt == null)
            {
                userChatLogColl.Insert(update);
            }
            else
            {
                userChatLogColl.Update(update);
            }
        }
Example #23
0
        public static void updateGameStat(UserInfo update)
        {
            UserInfo loginAttempt = userGameStatColl.FindOne(x => x.username == update.username);

            if (loginAttempt == null)
            {
                userGameStatColl.Insert(update);
            }
            else
            {
                userGameStatColl.Update(update);
            }
        }
Example #24
0
        public Block FindFirstBlock()
        {
            var min = _blocks.Min("Height");

            if (min.AsInt64 > 0)
            {
                return(_blocks.FindOne(Query.EQ("Height", min.AsInt64)));
            }
            else
            {
                return(null);
            }
        }
Example #25
0
 internal uint NextIP()
 {
     using (var random = RandomNumberGenerator.Create())
     {
         byte[] ipsegments = new byte[4];
         random.GetBytes(ipsegments);
         while (_addresses.FindOne(x => x.Address == this.CombineToUint(ipsegments)) != null)
         {
             random.GetBytes(ipsegments);
         }
         return(CombineToUint(ipsegments));
     }
 }
Example #26
0
        public bool Login(string usr, string pwd)
        {
            var user = _users.FindOne(u => u.Username == usr);

            if (user == null)
            {
                return(false);
            }
            if (!BCrypt.Net.BCrypt.Verify(pwd, user.Password))
            {
                return(false);
            }
            return(true);
        }
Example #27
0
        public void addKeyEntry(KeyEntry entry)
        {
            //if it exists update the current entry otherwise create it
            var results = mEntrys.FindOne(x => (x.Key == entry.Key && x.Secret == entry.Secret));

            if (results != null)
            {
                results.Value = entry.Value;
                mEntrys.Update(results);
            }
            else   //add the key entry to the database
            {
                mEntrys.Insert(entry);
            }
        }
Example #28
0
 public new ReturnPost Insert(entity.Admin data)
 {
     if (_col.FindOne(item => item.Name == data.Name) == null)
     {
         _col.Insert(data);
         return(new ReturnPost()
         {
             Data = data, Message = true
         });
     }
     return(new ReturnPost()
     {
         Message = false
     });
 }
Example #29
0
        //Register a device on a user
        public bool MobileRegister(Mobileunit mobileunit)
        {
            //No love if these variables are no good
            if (mobileunit.DeviceID.Length == 0 ||
                mobileunit.Displayname.Length == 0 ||
                GetUsername(mobileunit.UserID).Length == 0)
            {
                return(false);
            }

            //Add database access
            LiteCollection <Mobileunit> aDBValues = m_db.GetCollection <Mobileunit>("mobile");

            //Set the time for adding
            mobileunit.Added = DateTime.Now;

            //Check if it exists already
            //Add new mobile to register if not
            if (IsMobileRegistered(mobileunit.DeviceID, mobileunit.UserID))
            {
                var results = aDBValues.FindOne(x => x.DeviceID == mobileunit.DeviceID);
                mobileunit.Id = results.Id;
                aDBValues.Update(mobileunit);
            }
            else
            {
                aDBValues.Insert(mobileunit);
            }

            return(true);
        }
Example #30
0
        //Changes the password of a user
        public bool ChangePassword(int nID, string sPass)
        {
            if (sPass.Length == 0)
            {
                return(false);
            }

            LiteCollection <UserStructDb> aDBValues = m_db.GetCollection <UserStructDb>("users");
            UserStructDb results = aDBValues.FindOne(x => x.Id == nID);

            if (results == null)
            {
                return(false);
            }

            //Create new password
            byte[] plaintext = Encoding.ASCII.GetBytes(sPass + sUserSalt);

            // Generate additional entropy (will be used as the Initialization vector)
            byte[] entropy = new byte[15];
            using (RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider())
                rng.GetBytes(entropy);

            byte[] ciphertext = ProtectedData.Protect(plaintext, entropy, DataProtectionScope.LocalMachine);

            results.entropy    = entropy;
            results.ciphertext = ciphertext;
            aDBValues.Update(results);

            return(true);
        }