Ejemplo n.º 1
0
        public static string DetectPath(ServerDbs toString, bool allowAlernative = true)
        {
            if (File.Exists(toString))
            {
                return(toString);
            }

            string path = _getInCurrentPath(toString);

            if (path != null)
            {
                toString.UseSubPath = true;
                return(path);
            }

            path = _getInParentPath(toString);

            if (path == null && toString.AlternativeName != null && allowAlernative)
            {
                return(DetectPath(toString.AlternativeName));
            }

            toString.UseSubPath = false;
            return(path);
        }
Ejemplo n.º 2
0
        public DropEdit(string id, string dropChance, ServerDbs sdb, GenericDatabase gdb) : base("Item edit", "cde.ico", SizeToContent.Height, ResizeMode.NoResize)
        {
            _id         = id;
            _dropChance = dropChance;
            _sdb        = sdb;
            _gdb        = gdb;

            InitializeComponent();

            _tbChance.Text = _dropChance;
            _tbId.Text     = _id;

            PreviewKeyDown += new KeyEventHandler(_dropEdit_PreviewKeyDown);

            Loaded += delegate {
                _tbChance.SelectAll();
                _tbChance.Focus();
            };

            if (sdb != null)
            {
                _buttonQuery.Click += new RoutedEventHandler(_buttonQuery_Click);
            }
            else
            {
                _buttonQuery.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 3
0
        public static bool UseAlternative(ServerDbs toString)
        {
            if (FtpHelper.Exists(toString))
            {
                return(false);
            }

            string path = _getInCurrentPath(toString);

            if (path != null)
            {
                toString.UseSubPath = true;
                return(false);
            }

            path = _getInParentPath(toString);

            if (path == null && toString.AlternativeName != null)
            {
                path = DetectPath(toString.AlternativeName);

                return(path != null);
            }

            toString.UseSubPath = false;
            return(false);
        }
Ejemplo n.º 4
0
 public ValidationErrorView(ValidationErrors type, int itemId, string message, ServerDbs db, DbValidationEngine validationEngine)
 {
     Db               = db;
     Error            = type;
     Message          = message;
     Id               = itemId;
     ValidationEngine = validationEngine;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Gets the abstract database.
 /// </summary>
 /// <param name="name">The name of the database to get.</param>
 /// <returns></returns>
 public BaseDb TryGetDb(ServerDbs name)
 {
     if (_dbs.ContainsKey(name))
     {
         return(_dbs[name]);
     }
     return(null);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Adds a database object to this database.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="name">The name of the database.</param>
        /// <param name="db">The db.</param>
        public void AddDb <TKey>(ServerDbs name, AbstractDb <TKey> db)
        {
            _dbs[name] = db;

            // The commands executed on a database are only stored, they are not executed.
            // The database holder (this class) will execute them.
            db.Table.Commands.CommandExecuted     += (r, s) => Commands.Store(new GenericDbCommand <TKey>(db));
            db.Table.Commands.CommandIndexChanged += (r, s) => OnModified();
        }
Ejemplo n.º 7
0
        public static void OnExceptionThrown(ServerDbs primarytable, string subfile, BaseDb db)
        {
            DbEventHandler handler = ExceptionThrown;

            if (handler != null)
            {
                handler(null, primarytable, subfile, db);
            }
        }
Ejemplo n.º 8
0
        public static void OnStoppedLoading(ServerDbs primarytable, string subfile, BaseDb db)
        {
            DbEventHandler handler = StoppedLoading;

            if (handler != null)
            {
                handler(null, primarytable, subfile, db);
            }
        }
Ejemplo n.º 9
0
        public static void OnUpdate(ServerDbs primarytable, string subfile, string message)
        {
            DbWriteUpdateEventHandler handler = Update2;

            if (handler != null)
            {
                handler(null, primarytable, subfile, null, message);
            }
        }
Ejemplo n.º 10
0
        public static void OnCleared(ServerDbs primarytable, string subfile, BaseDb db)
        {
            DbEventHandler handler = Cleared;

            if (handler != null)
            {
                handler(null, primarytable, subfile, db);
            }
        }
Ejemplo n.º 11
0
        public static void OnWriteStatusUpdate(ServerDbs primarytable, string subfile, BaseDb db, string message)
        {
            DbWriteUpdateEventHandler handler = WriteStatusUpdate;

            if (handler != null)
            {
                handler(null, primarytable, subfile, db, message);
            }
        }
Ejemplo n.º 12
0
        public static void SelectList <TKey>(ServerDbs db, List <TKey> id)
        {
            if (id.Count == 0)
            {
                return;
            }

            Instance.SelectInternal(db, id);
        }
Ejemplo n.º 13
0
 public GTabSettings(ServerDbs serverDb, BaseDb gdb)
 {
     DbData              = serverDb;
     TabName             = new DisplayLabel(serverDb, gdb);
     GenerateSearchPopUp = true;
     CanBeDelayed        = true;
     CanChangeId         = true;
     AttIdWidth          = 60;
     SearchEngine        = new GSearchEngine <TKey, TValue>(serverDb.Filename, this);
 }
Ejemplo n.º 14
0
        public AttributeList Get(ServerDbs db)
        {
            var res = _allTables.Values.FirstOrDefault(p => p.DbSource == db);

            if (res == null)
            {
                throw new Exception("No table found which uses the ServerDb [" + db.Filename + "]");
            }

            return(res.AttributeList);
        }
Ejemplo n.º 15
0
        public AbstractDb <TKey> GetCopyDb <TKey>(ServerDbs db)
        {
            var res = _allTables.Values.FirstOrDefault(p => p.DbSource == db);

            if (res == null)
            {
                throw new Exception("No table found which uses the ServerDb [" + db.Filename + "]");
            }

            return(res.To <TKey>().Copy());
        }
Ejemplo n.º 16
0
        public static void WriteViewIds(ServerDbs dbSource, AbstractDb <int> db)
        {
            if (ProjectConfiguration.SynchronizeWithClientDatabases && dbSource == ServerDbs.Items &&
                ProjectConfiguration.HandleViewIds)
            {
                //return;
                int debugInfo = 0;
                _debugStatus = "OK";

                var dataAccId   = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId);
                var dataAccName = db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName);

                if (dataAccId != null && dataAccName != null)
                {
                    var itemDb1 = db.Get <int>(ServerDbs.Items);
                    var itemDb2 = db.Get <int>(ServerDbs.Items2);
                    var citemDb = db.Get <int>(ServerDbs.CItems);
                    debugInfo++;

                    try {
                        itemDb1.Commands.Begin();
                        itemDb2.Commands.Begin();
                        citemDb.Commands.Begin();
                        debugInfo++;

                        AccessoryTable table = new AccessoryTable(db, dataAccId, dataAccName);
                        table.SetLuaTables();
                        table.SetTables();
                        table.SetDbs();

                        _debugStatus = "BackupManager";
                        BackupEngine.Instance.BackupClient(ProjectConfiguration.SyncAccId, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccId));
                        BackupEngine.Instance.BackupClient(ProjectConfiguration.SyncAccName, db.ProjectDatabase.MetaGrf.GetData(ProjectConfiguration.SyncAccName));
                        debugInfo++;

                        _debugStatus = "WriteLuaFiles";
                        _writeLuaFiles(table.LuaAccIdParser, table.LuaAccNameParser, db);
                        debugInfo++;
                    }
                    catch (Exception err) {
                        ErrorHandler.HandleException("Couldn't save the accessory item files. Error code = " + debugInfo + ", state = " + _debugStatus, err, ErrorLevel.Low);
                        DbIOErrorHandler.Handle(err, "Generic exception while trying to save the client accessory items, debug code = " + debugInfo, ErrorLevel.NotSpecified);
                        DbIOErrorHandler.Focus();
                    }
                    finally {
                        itemDb1.Commands.End();
                        itemDb2.Commands.End();
                        citemDb.Commands.End();
                    }
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the meta table.
        /// </summary>
        /// <typeparam name="TKey">The type of the key.</typeparam>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public MetaTable <TKey> GetMetaTable <TKey>(ServerDbs name)
        {
            var table1    = ((AbstractDb <TKey>)_dbs[name]).Table;
            var metaTable = new MetaTable <TKey>(table1.AttributeList);

            metaTable.AddTable(table1);

            if (name.AdditionalTable != null)
            {
                metaTable.AddTable(((AbstractDb <TKey>)_dbs[name.AdditionalTable]).Table);
            }

            return(metaTable);
        }
Ejemplo n.º 18
0
 public void Select2(ServerDbs tabName, Tuple tuple)
 {
     if (tuple.Attributes.PrimaryAttribute.DataType == typeof(int))
     {
         SelectInternal(tabName, new List <int> {
             tuple.GetKey <int>()
         });
     }
     else if (tuple.Attributes.PrimaryAttribute.DataType == typeof(string))
     {
         SelectInternal(tabName, new List <string> {
             tuple.GetKey <string>()
         });
     }
 }
Ejemplo n.º 19
0
        public DropEditDialog(string id, string dropChance, ServerDbs sdb, SdeDatabase gdb, bool selectId = false, int flag = 0) : base("Item edit", "cde.ico", SizeToContent.Height, ResizeMode.NoResize)
        {
            _id         = id;
            _dropChance = dropChance;
            _sdb        = sdb;
            _gdb        = gdb;

            InitializeComponent();

            _tbChance.Text = _dropChance;
            _tbId.Text     = _id;

            PreviewKeyDown += new KeyEventHandler(_dropEdit_PreviewKeyDown);

            Loaded += delegate {
                if (selectId)
                {
                    _tbId.SelectAll();
                    _tbId.Focus();
                }
                else
                {
                    _tbChance.SelectAll();
                    _tbChance.Focus();
                }

                if ((flag & 1) == 1)
                {
                    _tbDStealProtected.Visibility = Visibility.Visible;
                    _tbStealProtected.Visibility  = Visibility.Visible;
                }

                if ((flag & 2) == 2)
                {
                    _tbDRandGroup.Visibility = Visibility.Visible;
                    _tbRandGroup.Visibility  = Visibility.Visible;
                }
            };

            if (sdb != null)
            {
                _buttonQuery.Click += new RoutedEventHandler(_buttonQuery_Click);
            }
            else
            {
                _buttonQuery.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 20
0
        public static string DetectPath(ServerDbs toString, bool allowAlernative = true)
        {
            if (toString == null)
            {
                return(null);
            }

            if (toString.IsClientSide && toString.ClientSidePath != null)
            {
                string dest = toString.ClientSidePath();

                if (!String.IsNullOrEmpty(dest))
                {
                    var tkpath = SdeEditor.Instance.ProjectDatabase.MetaGrf.FindTkPath(dest);

                    if (tkpath == null)
                    {
                        return(null);
                    }

                    return(tkpath.FilePath);
                }
            }

            if (FtpHelper.Exists(toString))
            {
                return(toString);
            }

            string path = _getInCurrentPath(toString);

            if (path != null)
            {
                toString.UseSubPath = true;
                return(path);
            }

            path = _getInParentPath(toString);

            if (path == null && toString.AlternativeName != null && allowAlernative)
            {
                return(DetectPath(toString.AlternativeName));
            }

            toString.UseSubPath = false;
            return(path);
        }
Ejemplo n.º 21
0
        public static void SelectList <TKey>(ServerDbs db, IEnumerable <TKey> id)
        {
            try {
                List <TKey> result = id.ToList();

                if (result.Count == 0)
                {
                    ErrorHandler.HandleException("No items match the query in [" + db.DisplayName + "].", ErrorLevel.NotSpecified);
                    return;
                }

                Instance.SelectInternal(db, result);
            }
            catch (Exception err) {
                ErrorHandler.HandleException("Failed to parse the search query.\r\n\r\n" + err.Message);
            }
        }
Ejemplo n.º 22
0
        public DisplayLabel(ServerDbs dbSource, BaseDb db) : this()
        {
            _dbSource = dbSource;
            _db       = db;
            _toString = dbSource.Filename;
            Content   = dbSource.DisplayName;

            if (_db != null)
            {
                _db.Attached.CollectionChanged += delegate(object sender, NotifyCollectionChangedEventArgs e) {
                    if (e.NewItems != null && e.NewItems.Count > 0 && e.Action == NotifyCollectionChangedAction.Replace || e.Action == NotifyCollectionChangedAction.Add)
                    {
                        if (e.NewItems[0] is KeyValuePair <string, object> )
                        {
                            var newItem = (KeyValuePair <string, object>)e.NewItems[0];

                            if (newItem.Key == "IsEnabled")
                            {
                                if (_db.Attached["IsEnabled"] == null || (bool)_db.Attached["IsEnabled"])
                                {
                                    _stateBrush         = Brushes.Black;
                                    _stateInactiveBrush = new SolidColorBrush(Color.FromArgb(255, 98, 98, 98));
                                }
                                else
                                {
                                    _stateBrush         = Brushes.Red;
                                    _stateInactiveBrush = Brushes.Red;
                                }

                                Grid    presenter = WpfUtilities.FindParentControl <Grid>(this);
                                TextBox box       = (TextBox)presenter.Children[2];

                                if (box.Text == "Visible")
                                {
                                    Foreground = _stateBrush;
                                }
                                else
                                {
                                    Foreground = _stateInactiveBrush;
                                }
                            }
                        }
                    }
                };
            }
        }
Ejemplo n.º 23
0
        public bool Load(ServerDbs dbSource)
        {
            DbSource = dbSource;
            string path = AllLoaders.DetectPath(DbSource);

            TextFileHelper.LatestFile = path;

            if (String.IsNullOrEmpty(path))
            {
                if (_db.ThrowFileNotFoundException)
                {
                    DbLoaderErrorHandler.Handle("File not found '" + DbSource + "'.", ErrorLevel.NotSpecified);
                }

                return(false);
            }

            FileType = AllLoaders.GetFileType(path);
            FilePath = path;
            AllLoaders.StoreFile(FilePath);
            return(true);
        }
Ejemplo n.º 24
0
        public bool Load(ServerDbs dbSource)
        {
            DbSource = dbSource;
            string path = DbPathLocator.DetectPath(DbSource);

            TextFileHelper.LatestFile = path;

            if (String.IsNullOrEmpty(path))
            {
                if (_db.ThrowFileNotFoundException)
                {
                    DbIOErrorHandler.Handle(StackTraceException.GetStrackTraceException(), "File not found '" + DbSource + "'.", ErrorLevel.NotSpecified);
                }

                return(false);
            }

            FileType = DbPathLocator.GetFileType(path);
            FilePath = path;
            DbPathLocator.StoreFile(FilePath);
            DbDebugHelper.OnLoaded(DbSource, FilePath, _db);
            return(true);
        }
Ejemplo n.º 25
0
        public DisplayLabel(ServerDbs dbSource, BaseDb db) : this()
        {
            _dbSource = dbSource;
            _db       = db;
            _toString = dbSource.Filename;
            Content   = dbSource.IsImport ? "imp" : dbSource.DisplayName;

            if (_db != null)
            {
                _db.IsEnabledChanged += (e, v) => {
                    this.Dispatch(delegate {
                        if (v)
                        {
                            _stateBrush         = Application.Current.Resources["TabItemTextSelectedForeground"] as SolidColorBrush;
                            _stateInactiveBrush = Application.Current.Resources["TabItemTextNormalForeground"] as SolidColorBrush;
                        }
                        else
                        {
                            _stateBrush         = Brushes.Red;
                            _stateInactiveBrush = Brushes.Red;
                        }

                        Grid presenter = WpfUtilities.FindParentControl <Grid>(this);
                        TextBox box    = (TextBox)presenter.Children[2];

                        if (box.Text == "Visible")
                        {
                            Foreground = _stateBrush;
                        }
                        else
                        {
                            Foreground = _stateInactiveBrush;
                        }
                    });
                };
            }
        }
Ejemplo n.º 26
0
        public DisplayLabel(ServerDbs dbSource, BaseDb db) : this()
        {
            _dbSource = dbSource;
            _db       = db;
            _toString = dbSource.Filename;
            Content   = dbSource.IsImport ? "imp" : dbSource.DisplayName;

            if (_db != null)
            {
                _db.IsEnabledChanged += (e, v) => {
                    this.Dispatch(delegate {
                        if (v)
                        {
                            _stateBrush         = Brushes.Black;
                            _stateInactiveBrush = new SolidColorBrush(Color.FromArgb(255, 215, 215, 215));
                        }
                        else
                        {
                            _stateBrush         = Brushes.Red;
                            _stateInactiveBrush = Brushes.Red;
                        }

                        Grid presenter = WpfUtilities.FindParentControl <Grid>(this);
                        TextBox box    = (TextBox)presenter.Children[2];

                        if (box.Text == "Visible")
                        {
                            Foreground = _stateBrush;
                        }
                        else
                        {
                            Foreground = _stateInactiveBrush;
                        }
                    });
                };
            }
        }
Ejemplo n.º 27
0
        public override void ButtonClicked()
        {
            if (!_isLoaded)
            {
                _init();
            }

            int value;

            ((MenuItem)_button.ContextMenu.Items[0]).IsEnabled = Int32.TryParse(_textBox.Text, out value) && value > 0;

            try {
                string val = "Unknown";

                if (value <= 0)
                {
                }
                else
                {
                    ServerDbs sdb = (ServerDbs)_attribute.AttachedObject;

                    MetaTable <int> table = ((GenericDatabase)_tab.Database).GetMetaTable <int>(sdb);
                    Tuple           tuple = table.TryGetTuple(value);

                    if (tuple != null)
                    {
                        val = tuple.GetValue(table.AttributeList.Attributes.FirstOrDefault(p => p.IsDisplayAttribute) ?? table.AttributeList.Attributes[1]).ToString();
                    }
                }

                _select.Header = String.Format("Select '{0}'", val);
            }
            catch { }

            _button.ContextMenu.IsOpen = true;
        }
Ejemplo n.º 28
0
 public bool Write(ServerDbs dbSource, string dbPath, string subPath, ServerType serverType, FileType fileType = FileType.Detect, bool isModifiedCheck = false)
 {
     DbSource = dbSource;
     return(Write(dbPath, subPath, serverType, fileType, isModifiedCheck));
 }
Ejemplo n.º 29
0
 public AbstractDb <T> GetDb <T>(ServerDbs source)
 {
     return(ProjectDatabase.GetDb <T>(source));
 }
Ejemplo n.º 30
0
 public MetaTable <T> GetMetaTable <T>(ServerDbs db)
 {
     return(ProjectDatabase.GetMetaTable <T>(db));
 }