private void LoadGameObjects()
 {
     CultureInfo culture = Settings.DatabaseCulture;
     Observable.Start(() =>
         {
             int minId = 0;
             // load a bunch of objects from database
             var provider = new MangosProvider();
             return provider.GetGameObjects(culture)
                 .Where(o => o.Type == (int)MangosTEx.Services.DataTypes.GameObjectType.TEXT)
                 //.Where(o => o.Id > minId)
                 .Take(150)
                 .ToList();
         })
         .ObserveOnDispatcher()
         .Subscribe(result =>
         {
             GameObjects = result;
             UpdateGameObjectLocaleEvent += OnUpdateGameObjectLocale;
             Task.Factory.StartNew(() => GetGameObjectsLocales(result));
         }, OnError);
 }
        private void LoadDataAsync()
        {
            CultureInfo culture = Settings.DatabaseCulture;
            // get a processId so we can stop it if the user request a new batch before we finished this one
            int processId = ++_loadProcessId;
            SetCollectionView(null);
            Observable.Start(() =>
                {
                    // load items from database
                    using (var provider = new MangosProvider())
                    using (new PerformanceChecker("GetQuests"))
                    {
                        return provider.GetQuests(culture)
                            .Where(o => o.Id >= 9874 && o.Id <= 9888)
                            .Select(o => new LocalizedQuest(o))
                            .ToList();
                    }
                })
                .ObserveOnDispatcher()
                .Subscribe(result =>
                {
                    // check processId to make sure the user has not requested another batch meantime
                    if (processId != _loadProcessId)
                        return;

                    // display loaded items to user
                    SetCollectionView(result);
                }, OnError);
        }
        private void UpdateDatabaseAsync(IEnumerable<LocalizedQuest> items)
        {
            CultureInfo culture = Settings.DatabaseCulture;
            Observable.Start(() =>
            {
                // select valid items and convert them to update database
                var dbItems = items
                    .Where(o => string.IsNullOrEmpty(o.Error) == false)
                    .Select(GetTranslatedDbItem);

                using (var provider = new MangosProvider())
                {
                    dbItems = provider.UpdateQuests(dbItems, culture)
                        .ToList();
                }
                items.Join(dbItems, o => o.DatabaseEntity.Id, o => o.Id, (li, dbi) => new { li, dbi })
                    .ToList()
                    .ForEach(o => o.li.DatabaseEntity = o.dbi);
            });
        }
        private void UpdateDatabaseAsync(IEnumerable<LocalizedItem> items)
        {
            CultureInfo culture = Settings.DatabaseCulture;
            Observable.Start(() =>
            {
                // select items to update and convert them
                var dbItems = items
                    //.Where(o => o.Status == LocalizationStatus.NotEqual)
                    .Select(GetTranslatedDbItem);

                if (dbItems.Any() == false)
                    return;

                using (var provider = new MangosProvider())
                {
                    dbItems = provider.UpdateItems(dbItems, culture)
                        .ToList();
                }

                // refresh updated items
                items.Join(dbItems, o => o.DatabaseEntity.Id, o => o.Id, (li, dbi) => new { li, dbi })
                    .ToList()
                    .ForEach(o => o.li.DatabaseEntity = o.dbi);
            });
        }