示例#1
0
        /// <summary>
        /// Checks for specified reference and updates issues list
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="cell"></param>
        /// <param name="issues"></param>
        private void _CheckReferenceValue(DB.Topic topic, DB.Cell cell, Collection <DatabaseFixer.Corruption> issues)
        {
            if (cell.optionalRef != null && issues != null)
            {
                string   topicId         = cell.optionalRef;
                DB.Topic referencedTopic = DB.TopicPerTopicId[topicId];

                if (referencedTopic == DB.Topic.None)
                {
                    // Report unknown topic
                    DatabaseFixer.Corruption newCorruption = new DatabaseFixer.Corruption
                    {
                        corruptedCell  = cell,
                        corruptedValue = topicId,
                        culture        = DB.Culture.Global,
                        entryId        = cell.entryIndex,
                        kind           =
                            DatabaseFixer.CorruptionKind.
                            UnknownReferencedTopic,
                        referencedTopic = DB.Topic.None,
                        topic           = topic
                    };

                    issues.Add(newCorruption);
                }
                else
                {
                    // Getting referenced topic
                    TduFile[] databaseItems = _LoadedData[referencedTopic];
                    DB        dbTopic       = databaseItems[0] as DB;

                    if (dbTopic == null)
                    {
                        throw new Exception("Unable to get database information for topic: " + referencedTopic);
                    }

                    // Get referenced value
                    List <DB.Entry> referencedEntries = DatabaseHelper.SelectAllCellsFromTopicWherePrimaryKey(dbTopic, cell.value);

                    if (referencedEntries.Count == 0)
                    {
                        // Report missing reference
                        DatabaseFixer.Corruption newCorruption = new DatabaseFixer.Corruption
                        {
                            corruptedCell  = cell,
                            corruptedValue = cell.value,
                            culture        = DB.Culture.Global,
                            entryId        = cell.entryIndex,
                            kind           =
                                DatabaseFixer.CorruptionKind.MissingReference,
                            referencedTopic = dbTopic.CurrentTopic,
                            topic           = topic
                        };

                        issues.Add(newCorruption);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Checks cell value for specified resource and updates issues list
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="cell"></param>
        /// <param name="dbResource"></param>
        /// <param name="issues"></param>
        /// <returns></returns>
        private void _CheckResourceValue(DB.Topic topic, DB.Cell cell, DBResource dbResource, Collection <DatabaseFixer.Corruption> issues)
        {
            if (dbResource == null)
            {
                // Resource from another topic
                if (cell.optionalRef != null)
                {
                    DB.Topic referencedTopic = DB.TopicPerTopicId[cell.optionalRef];

                    // Is topic to be loaded ?
                    TduFile[] databaseItems = _LoadedData[referencedTopic];

                    dbResource = databaseItems[1] as DBResource;

                    if (dbResource == null)
                    {
                        throw new Exception("Unable to get database resource information for referenced topic: " + referencedTopic);
                    }
                }
            }

            if (dbResource == null)
            {
                throw new Exception("Unable to get database resource information for topic: " + topic);
            }

            if (!dbResource.GetEntryFromId(cell.value).isValid)
            {
                // Report missing resource
                DatabaseFixer.Corruption newCorruption = new DatabaseFixer.Corruption
                {
                    corruptedCell  = cell,
                    corruptedValue = cell.value,
                    culture        = dbResource.CurrentCulture,
                    entryId        = cell.entryIndex,
                    kind           =
                        DatabaseFixer.CorruptionKind.MissingResource,
                    referencedTopic = dbResource.CurrentTopic,
                    topic           = topic
                };

                issues.Add(newCorruption);
            }
        }
示例#3
0
        /// <summary>
        /// Checks for bugs in entry structure
        /// </summary>
        /// <param name="topic"></param>
        /// <param name="entry"></param>
        /// <param name="issues"></param>
        private static void _CheckStructure(DB topic, DB.Entry entry, Collection <DatabaseFixer.Corruption> issues)
        {
            if (topic != null)
            {
                // Cell count
                if (topic.Structure.Count != entry.cells.Count)
                {
                    DatabaseFixer.Corruption newCorruption = new DatabaseFixer.Corruption
                    {
                        culture = DB.Culture.Global,
                        entryId = entry.index,
                        kind    =
                            DatabaseFixer.CorruptionKind.StructureMissingColumns,
                        referencedTopic = DB.Topic.None,
                        topic           = topic.CurrentTopic,
                        comment         = "Missing columns: " + (topic.Structure.Count - entry.cells.Count)
                    };

                    issues.Add(newCorruption);
                }
            }
        }