示例#1
0
        private void _clientDbExport(FileType fileType)
        {
            try {
                if (_isClientSyncConvert())
                {
                    if (_delayedReloadDatabase)
                    {
                        if (!ReloadDatabase())
                        {
                            return;
                        }
                        _asyncOperation.WaitUntilFinished();
                    }

                    string path = this.Dispatch(p => PathRequest.FolderExtractDb());

                    if (path == null)
                    {
                        return;
                    }

                    Progress = -1;
                    this.Dispatch(p => p._mainTabControl.IsEnabled = false);
                    var db = _clientDatabase.GetDb <int>(ServerDbs.CItems);
                    DbIOClientItems.WriterSub(null, db, path, fileType);
                    OpeningService.FileOrFolder(path);
                }
                else
                {
                    ErrorHandler.HandleException("You must synchronize the client databases first. Go in the settings page.");
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
            }
            finally {
                Progress = 100;
                this.Dispatch(p => p._mainTabControl.IsEnabled = true);
            }
        }
示例#2
0
        private BaseTable _loadClientDb(string file)
        {
            AbstractDb <int> db = AllTables.First(p => p.Value.DbSource == ServerDbs.CItems).Value.To <int>().Copy();

            db.DummyInit(this);

            if (db.DbSource == ServerDbs.CItems)
            {
                if (file.IsExtension(".lua", ".lub"))
                {
                    db.DbLoader = (d, idb) => DbIOClientItems.LoadEntry(db, file);
                }
                else
                {
                    db.DbLoader = (d, idb) => DbIOClientItems.LoadData(db, file, _getMappingField(file), _getAllowcutLine(file));
                }
            }

            var method = db.DbLoader;

            db.DbLoader = (d, idb) => {
                db.Table.EnableRawEvents = false;
                method(d, idb);
                db.Table.Commands.ClearCommands();
            };

            try {
                DebugStreamReader.ToClientEncoding = true;
                db.LoadFromClipboard(file);
            }
            finally {
                DebugStreamReader.ToClientEncoding = false;
            }

            return(db.Table);
        }
示例#3
0
        public void Map <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, string file, DbAttribute[] mappedFields)
        {
            AbstractDb <TKey> db = GetCopyDb <TKey>(DbImport);

            db.DummyInit(tab.ProjectDatabase);

            if (db.DbSource == ServerDbs.CItems)
            {
                if (file.IsExtension(".lua", ".lub"))
                {
                    db.DbLoader = (d, idb) => DbIOClientItems.LoadEntry((AbstractDb <int>)(object) db, file);
                }
                else
                {
                    db.DbLoader = (d, idb) => DbIOClientItems.LoadData((AbstractDb <int>)(object) db, file, mappedFields[0], _allowCutLine);
                }
            }

            var method = db.DbLoader;

            db.DbLoader = (d, idb) => {
                db.Table.EnableRawEvents = false;
                method(d, idb);
            };

            try {
                if ((tab.DbComponent.DbSource & ServerDbs.CItems) != ServerDbs.CItems)
                {
                    DebugStreamReader.ToServerEncoding = true;
                }
                else
                {
                    DebugStreamReader.ToClientEncoding = true;
                }

                db.LoadFromClipboard(file);
            }
            finally {
                DebugStreamReader.ToServerEncoding = false;
                DebugStreamReader.ToClientEncoding = false;
            }

            var table = tab.Table;

            table.Commands.Begin();

            try {
                foreach (var cTuple in db.Table.FastItems)
                {
                    var sTuple = table.TryGetTuple(cTuple.Key);
                    if (sTuple == null)
                    {
                        continue;
                    }

                    for (int i = 0; i < mappedFields.Length; i += 2)
                    {
                        var cValue = cTuple.GetValue <string>(mappedFields[i]);
                        var sValue = sTuple.GetValue <string>(mappedFields[i + 1]);

                        if (cValue != sValue)
                        {
                            if (_isNoEmptyFields(mappedFields[i + 1], cValue, sValue))
                            {
                                continue;
                            }
                            table.Commands.Set(sTuple, mappedFields[i + 1], cValue);
                        }
                    }
                }
            }
            catch (Exception err) {
                ErrorHandler.HandleException(err);
                table.Commands.CancelEdit();
            }
            finally {
                table.Commands.EndEdit();
            }
        }