public static DbHolder UpdateDbHolder(DTOHolder dtoHolder, DbHolder holder, IList <DbAccount> accounts)
 {
     holder.Name     = dtoHolder.Name;
     holder.Surname  = dtoHolder.Surname;
     holder.Accounts = accounts;
     return(holder);
 }
예제 #2
0
        public static string tryCreate(string token, string hubName)
        {
            User user = User.getAutentification(token);

            if (user == null)
            {
                return(new ErrorResponse(300, Constants.NetMsg.FORBIDDEN).ToJson());
            }

            var hubs = DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <Hub>(Constants.HUBS_TABLE_NAME);

            long count = hubs.Find(Builders <Hub> .Filter.Eq <String>(e => e.name, hubName)).Count();

            if (count > 0)
            {
                return(new ErrorResponse(220, Constants.NetMsg.HUB_ALREADY_EXISTS).ToJson());
            }

            Hub hub = new Hub(hubName, user);

            hubs.InsertOne(hub);

            //Player player = new Player(hub.id.ToString());
            return(new IdResponse(hub.id.ToString()).ToJson());
        }
예제 #3
0
        /// <summary>
        /// 初始化数据库运行环境
        /// </summary>
        /// <param name="holder">存储数据库实例的方法</param>
        public static void InitializeEnvironment(DbHolder holder = null)
        {
            if (holder == null)
            {
                holder = new WebDbHolder();
            }

            _holder = holder;
        }
예제 #4
0
 public static Hub get(string id)
 {
     try {
         return(DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <Hub>(Constants.HUBS_TABLE_NAME)
                .Find(Builders <Hub> .Filter.Eq <ObjectId>(hub => hub.id, new ObjectId(id))).First());
     } catch {
         return(null);
     }
 }
예제 #5
0
 public static User getAutentification(string token)
 {
     try {
         return(DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <User>(Constants.USERS_TABLE_NAME)
                .Find(Builders <User> .Filter.Eq <String>(e => e.token, token)).First());
     } catch {
         return(null);
     }
 }
예제 #6
0
 public static User get(string id)
 {
     try {
         var  collection = DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <User>(Constants.USERS_TABLE_NAME);
         User user       = collection.Find(Builders <User> .Filter.Eq <String>(u => u.id.ToString(), id)).First();
         return(user);
     } catch {
         return(null);
     }
 }
예제 #7
0
        public void Add(TabControl mainTabControl, DbHolder holder, TabNavigation tabEngine, SdeEditor editor)
        {
            holder.AddTable(_adb);
            GDbTab copy = holder.GetTab(_adb, mainTabControl);

            if (_adb is AbstractDb <int> )
            {
                _adb.To <int>().Table.Commands.CommandIndexChanged += (e, a) => editor.UpdateTabHeader(_adb.To <int>());
            }
            else if (_adb is AbstractDb <string> )
            {
                _adb.To <string>().Table.Commands.CommandIndexChanged += (e, a) => editor.UpdateTabHeader(_adb.To <string>());
            }

            copy._listView.SelectionChanged += delegate(object sender, SelectionChangedEventArgs args) {
                if (sender is ListView)
                {
                    ListView view = (ListView)sender;
                    tabEngine.StoreAndExecute(new SelectionChanged(copy.Header.ToString(), view.SelectedItem, view, copy));
                }
            };

            ((DisplayLabel)copy.Header).ContextMenu.Items.Cast <MenuItem>().ToList().ForEach(p => p.IsEnabled = true);

            MenuItem mitem = new MenuItem();

            mitem.Icon = new Image {
                Source = ApplicationManager.GetResourceImage("delete.png")
            };
            mitem.Header = "Delete table";
            mitem.Click += delegate {
                holder.RemoveTable(_adb);
                mainTabControl.Items.Remove(copy);

                List <string> tabs = ProjectConfiguration.CustomTabs;
                tabs.Remove(_file);
                ProjectConfiguration.CustomTabs = tabs.Distinct().ToList();
            };

            ((DisplayLabel)copy.Header).ContextMenu.Items.Add(mitem);

            mainTabControl.Items.Insert(mainTabControl.Items.Count, copy);
            _adb.LoadDb();

            if (_adb is AbstractDb <int> )
            {
                copy.To <int>().SearchEngine.Filter(this);
            }
            else if (_adb is AbstractDb <string> )
            {
                copy.To <string>().SearchEngine.Filter(this);
            }

            editor.GdTabs.Add(copy);
        }
        public void Add(DTOHolder item)
        {
            var holder = new DbHolder
            {
                Id = item.Id
            };
            var accounts = ToAccounts(item.Accounts);

            holder = HolderMapper.UpdateDbHolder(item, holder, accounts);
            _bankContext.Holders.Add(holder);
        }
        public static DTOHolder ToDTOHolder(this DbHolder holder)
        {
            var accounts = (holder.Accounts != null) ? (from acc in holder.Accounts select acc.Id).ToList() : new List <long>();

            return(new DTOHolder()
            {
                Id = holder.Id,
                Name = holder.Name,
                Surname = holder.Surname,
                Accounts = accounts
            });
        }
예제 #10
0
        public static User trySignUp(string name, string login, string password)
        {
            IMongoCollection <User> users = DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <User>(Constants.USERS_TABLE_NAME);

            long count = users.Find(Builders <User> .Filter.Eq <String>(u => u.login, login)).Count();

            if (count > 0)
            {
                return(null);
            }

            string salt = Utility.randomSalt();
            User   user = new User(login, Utility.sha256(password + salt + Settings.getServerKey()), salt, name, null);

            users.InsertOne(user);
            return(user);
        }
예제 #11
0
 public static User tryLogin(string login, string password)
 {
     try {
         var  collection = DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <User>(Constants.USERS_TABLE_NAME);
         User user       = collection.Find(Builders <User> .Filter.Eq <String>(u => u.login, login)).First();
         if (user.password != Utility.sha256(password + user.salt + Settings.getServerKey()))
         {
             return(null);
         }
         user.token = Guid.NewGuid().ToString();
         collection.FindOneAndUpdate(
             Builders <User> .Filter.Eq <ObjectId>(e => e.id, user.id),
             Builders <User> .Update.Set(e => e.token, user.token)
             );
         return(user);
     } catch {
         return(null);
     }
 }
예제 #12
0
        public bool Init(DbHolder holder)
        {
            try {
                if (!File.Exists(_file))
                {
                    return(false);
                }

                string   dbRawName = Path.GetFileNameWithoutExtension(_file);
                string   dbName    = _toDbName(dbRawName.Replace("_db", ""));
                string[] lines     = File.ReadAllLines(_file);
                string[] itemsRaw  = null;
                bool     waitOne   = false;

                foreach (string line in lines)
                {
                    string t = line;

                    string[] raw = t.Replace("[,", ",[").Replace("{,", ",{").Split(',');

                    if (waitOne && raw.Length <= 1)
                    {
                        break;
                    }

                    if (waitOne)
                    {
                        raw[0]   = raw[0].TrimStart('/', ' ', '\t');
                        itemsRaw = itemsRaw.Concat(raw).ToArray();
                    }
                    else
                    {
                        itemsRaw = raw;
                    }

                    if (itemsRaw.Length > 1)
                    {
                        int end = itemsRaw.Length - 1;
                        itemsRaw[end] = itemsRaw[end].Contains("//") ? itemsRaw[end].Substring(0, itemsRaw[end].IndexOf("//", StringComparison.Ordinal)) : itemsRaw[end];
                        waitOne       = true;
                    }
                }

                if (itemsRaw == null || itemsRaw.Length <= 1)
                {
                    return(false);
                }

                Dictionary <int, string> comments = new Dictionary <int, string>();

                foreach (string line in lines)
                {
                    if (!line.StartsWith("//"))
                    {
                        break;
                    }

                    string bufLine = line.Trim('/', ' ');

                    if (bufLine.Length > 2 && bufLine[2] == '.')
                    {
                        int ival;

                        if (Int32.TryParse(bufLine.Substring(0, 2), out ival))
                        {
                            string t = bufLine.Substring(3).Trim(' ', '\t');

                            int index = t.LastIndexOf("  ", StringComparison.Ordinal);

                            if (index > -1)
                            {
                                t = t.Substring(index);
                            }
                            else
                            {
                                index = t.LastIndexOf("\t\t", StringComparison.Ordinal);

                                if (index > -1)
                                {
                                    t = t.Substring(index);
                                }
                            }

                            comments[ival] = t.Trim(' ', '\t');
                        }
                    }
                }

                List <string> items = itemsRaw.ToList();

                items[0] = items[0].TrimStart('/', ' ');
                items    = items.ToList().Select(p => p.Trim(' ')).ToList();
                HashSet <int> variable = new HashSet <int>();

                if (items.Any(p => p == "..."))
                {
                    // Find the longest line

                    if (_hasLogic(items, variable))
                    {
                    }
                    else
                    {
                        int        itemIndex = items.IndexOf("...");
                        List <int> count     = lines.Select(line => line.Split(',').Length).ToList();

                        int missingArguments = count.Max(p => p) - items.Count;

                        if (missingArguments == 0)
                        {
                            items[itemIndex] = "Unknown";
                        }
                        else if (missingArguments < 0)
                        {
                            items.RemoveAt(itemIndex);
                        }
                        else
                        {
                            items.RemoveAt(itemIndex);

                            for (int i = 0; i < missingArguments; i++)
                            {
                                items.Insert(itemIndex, "Variable");
                                variable.Add(itemIndex + i);
                            }
                        }
                    }
                }

                if (items.Any(p => p.Contains('[')) || items.Any(p => p.Contains('{')))
                {
                    bool begin = false;

                    for (int i = 0; i < items.Count; i++)
                    {
                        if (items[i].StartsWith("[") || items[i].StartsWith("{"))
                        {
                            if (items[i] != "{}")
                            {
                                begin = true;
                            }
                        }

                        if (begin)
                        {
                            variable.Add(i);
                        }

                        if (items[i].EndsWith("]") || items[i].EndsWith("}"))
                        {
                            begin = false;
                        }
                    }
                }

                items = items.Select(p => p.Trim('[', ']', '{', '}')).ToList();

                AttributeList list = new AttributeList();

                IntLineStream reader = new IntLineStream(_file);
                Type          dbType = typeof(int);

                bool?duplicates = reader.HasDuplicateIds();

                if (duplicates == null || duplicates == true)
                {
                    dbType = typeof(string);
                }

                bool        first            = true;
                DbAttribute bindingAttribute = null;

                for (int i = 0; i < items.Count; i++)
                {
                    string      value     = items[i];
                    string      desc      = null;
                    string      toDisplay = _toDisplay(value);
                    DbAttribute att;

                    if (comments.ContainsKey(i + 1))
                    {
                        desc = comments[i + 1];
                    }

                    if (i == 0 && first)
                    {
                        if (duplicates == null)
                        {
                            att = new PrimaryAttribute(value, dbType, 0, toDisplay);
                        }
                        else if (duplicates == true)
                        {
                            att   = new PrimaryAttribute("RealId", dbType, "");
                            first = false;
                            i--;
                        }
                        else
                        {
                            att = new PrimaryAttribute(value, dbType, 0, toDisplay);
                        }
                    }
                    else
                    {
                        string          toLower = value.ToLower();
                        CustomAttribute custom  = new CustomAttribute(value, typeof(string), "", toDisplay, desc);
                        att = custom;

                        if (toLower.Contains("skillid"))
                        {
                            att.AttachedObject = ServerDbs.Skills;
                            custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty <int>) : typeof(SelectTupleProperty <string>));
                            if (i == 1)
                            {
                                bindingAttribute = new DbAttribute("Elements", typeof(SkillBinding), duplicates == true ? 2 : 1)
                                {
                                    IsDisplayAttribute = true, Visibility = VisibleState.Hidden
                                }
                            }
                            ;
                        }

                        if (toLower.Contains("mobid"))
                        {
                            att.AttachedObject = ServerDbs.Mobs;
                            custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty <int>) : typeof(SelectTupleProperty <string>));
                            if (i == 1)
                            {
                                bindingAttribute = new DbAttribute("Elements", typeof(MobBinding), duplicates == true ? 2 : 1)
                                {
                                    IsDisplayAttribute = true, Visibility = VisibleState.Hidden
                                }
                            }
                            ;
                        }

                        if (toLower.Contains("itemid"))
                        {
                            att.AttachedObject = ServerDbs.Items;
                            custom.SetDataType(dbType == typeof(int) ? typeof(SelectTupleProperty <int>) : typeof(SelectTupleProperty <string>));
                            if (i == 1)
                            {
                                bindingAttribute = new DbAttribute("Elements", typeof(ItemBinding), duplicates == true ? 2 : 1)
                                {
                                    IsDisplayAttribute = true, Visibility = VisibleState.Hidden
                                }
                            }
                            ;
                        }

                        if (variable.Contains(i))
                        {
                            att.IsSkippable = true;
                        }
                    }

                    list.Add(att);
                }

                if (bindingAttribute != null)
                {
                    list.Add(bindingAttribute);
                }
                else
                {
                    string toLower = items[0].ToLower();

                    if (toLower.Contains("skillid"))
                    {
                        bindingAttribute = new DbAttribute("Elements", typeof(SkillBinding), duplicates == true ? 2 : 1)
                        {
                            IsDisplayAttribute = true, Visibility = VisibleState.Hidden
                        };
                    }

                    if (toLower.Contains("mobid"))
                    {
                        bindingAttribute = new DbAttribute("Elements", typeof(MobBinding), duplicates == true ? 2 : 1)
                        {
                            IsDisplayAttribute = true, Visibility = VisibleState.Hidden
                        };
                    }

                    if (toLower.Contains("itemid"))
                    {
                        bindingAttribute = new DbAttribute("Elements", typeof(ItemBinding), duplicates == true ? 2 : 1)
                        {
                            IsDisplayAttribute = true, Visibility = VisibleState.Hidden
                        };
                    }

                    if (bindingAttribute != null)
                    {
                        list.Add(bindingAttribute);
                    }
                }


                if (dbType == typeof(int))
                {
                    _adb = new DummyDb <int>();

                    _adb.To <int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromMobDb;
                    _adb.To <int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromItemDb;
                    _adb.To <int>().TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromSkillDb;
                }
                else
                {
                    _adb = new DummyDb <string>();

                    var db = _adb.To <string>();

                    if (duplicates == true)
                    {
                        db.LayoutIndexes = new int[] {
                            1, list.Attributes.Count
                        };

                        db.DbLoader = DbLoaderMethods.DbUniqueLoader;
                        db.DbWriter = DbWriterMethods.DbUniqueWriter;

                        db.TabGenerator.OnInitSettings += delegate(GDbTabWrapper <string, ReadableTuple <string> > tab, GTabSettings <string, ReadableTuple <string> > settings, BaseDb gdb) {
                            settings.CanChangeId         = false;
                            settings.CustomAddItemMethod = delegate {
                                try {
                                    string id = Methods.RandomString(32);

                                    ReadableTuple <string> item = new ReadableTuple <string>(id, settings.AttributeList);
                                    item.Added = true;

                                    db.Table.Commands.StoreAndExecute(new AddTuple <string, ReadableTuple <string> >(id, item));
                                    tab._listView.ScrollToCenterOfView(item);
                                }
                                catch (KeyInvalidException) {
                                }
                                catch (Exception err) {
                                    ErrorHandler.HandleException(err);
                                }
                            };
                        };
                        db.TabGenerator.StartIndexInCustomMethods = 1;
                        db.TabGenerator.OnInitSettings           += delegate(GDbTabWrapper <string, ReadableTuple <string> > tab, GTabSettings <string, ReadableTuple <string> > settings, BaseDb gdb) {
                            settings.AttributeList = gdb.AttributeList;
                            settings.AttId         = gdb.AttributeList.Attributes[1];
                            settings.AttDisplay    = gdb.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? gdb.AttributeList.Attributes[2];
                            settings.AttIdWidth    = 60;
                        };
                        db.TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromMobDbString;
                        db.TabGenerator.OnSetCustomCommands += GTabsMaker.SelectFromSkillDbString;
                    }
                    else if (duplicates == null)
                    {
                        db.UnsafeContext = true;
                        db.DbWriter      = DbWriterMethods.DbStringCommaWriter;
                    }
                }

                ServerDbs sdb = ServerDbs.Instantiate(dbRawName, dbName, FileType.Txt);

                if (bindingAttribute != null)
                {
                    bindingAttribute.AttachedObject = _adb;
                }

                _adb.IsCustom      = true;
                _adb.DbSource      = sdb;
                _adb.AttributeList = list;

                return(true);
            }
            catch { }
            return(false);
        }
예제 #13
0
 public static DbAccount UpdateDbAccount(DTOAccount dtoAccount, DbAccount account, DbHolder holder)
 {
     account.AccountType = dtoAccount.AccountType;
     account.Balance     = dtoAccount.Balance;
     account.Bonus       = dtoAccount.Bonus;
     account.Holder      = holder;
     account.IsEnabled   = dtoAccount.IsEnabled;
     return(account);
 }
예제 #14
0
 public static List <HubInfo> find(string query)
 {
     return(DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <Hub>(Constants.HUBS_TABLE_NAME)
            .Find(Builders <Hub> .Filter.Regex(Constants.HUB_NAME, query)).ToList().ConvertAll(el => new HubInfo(el.id.ToString(), el.name, el.owner.name)));
 }
예제 #15
0
 public static List <HubInfo> getAll()
 {
     return(DbHolder.getDb().GetDatabase(Constants.HUBBL_DB_NAME).GetCollection <Hub>(Constants.HUBS_TABLE_NAME)
            .Find(_ => true).ToList().ConvertAll(el => new HubInfo(el.id.ToString(), el.name, el.owner.name)));
 }