Beispiel #1
0
 private RecordStructure(RecordsRecord rec, SubrecordBase[] subrecordTree, SubrecordStructure[] subrecords)
 {
     this.name = rec.name;
     this.description = rec.desc;
     this.subrecordTree = subrecordTree;
     this.subrecords = subrecords;
 }
Beispiel #2
0
        /// <summary>
        ///     Update records using another record list.
        /// </summary>
        /// <param name="baseRecord">
        ///     The base Record.
        /// </param>
        /// <param name="updateRecord">
        ///     The update Record.
        /// </param>
        internal void MergeRecord(RecordsRecord baseRecord, RecordsRecord updateRecord)
        {
            if (baseRecord == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(baseRecord.desc) || updateRecord.desc != baseRecord.desc)
            {
                updateRecord.desc = baseRecord.desc;
            }

            foreach (var sr in updateRecord.AllSubrecords)
            {
                MergeRecord(baseRecord.AllSubrecords.FirstOrDefault(a => a.name == sr.name), sr);
            }
        }
Beispiel #3
0
        private bool CreateSubrecords(RecordsRecord rr, Record r)
        {
            // int srIdx = 0;
            var groups = from psr in r.SubRecords
                         group psr by psr.Name
                         into g select new {Name = g.Key, Records = g.ToArray()};

            int lastIndex = 0;
            var dict = new Dictionary<string, Subrecord>();
            foreach (var kvp in groups)
            {
                if (IsCanceled)
                {
                    return false;
                }

                // if (kvp.Name.Count(a => !Char.IsLetterOrDigit(a)) > 0) continue;
                int n = kvp.Records.Length;

                var sr = rr.Subrecords.FirstOrDefault(x => x.name == kvp.Name);
                if (sr == null)
                {
                    sr = new Subrecord();
                    sr.name = sr.desc = kvp.Name;
                    sr.optional = 1;
                    if (lastIndex + 1 <= rr.Items.Count)
                    {
                        rr.Items.Insert(++lastIndex, sr);
                    }
                    else
                    {
                        rr.Items.Add(sr);
                    }
                }
                else
                {
                    lastIndex = rr.Items.IndexOf(sr, (lastIndex < 0) ? lastIndex : 0);
                    if (lastIndex < 0)
                    {
                        // out of order
                        lastIndex = rr.Items.IndexOf(sr);
                    }
                }

                // Group Detection
                if (n > 0)
                {
                    int idx1 = r.SubRecords.IndexOf(kvp.Records[0]);
                    int idx2 = idx1;
                    for (int i = 1; i < n; ++i, idx1 = idx2)
                    {
                        idx2 = r.SubRecords.IndexOf(kvp.Records[i]);
                        int diff = r.SubRecords.Skip(idx1).Take(idx2 - idx1).Select((a) => a.Name).Distinct().Count();
                        if (diff > sr.repeat)
                        {
                            sr.optional = sr.repeat = diff;
                        }
                    }

                    if (sr.repeat == 0 && n > 1)
                    {
                        sr.optional = sr.repeat = 1;
                    }
                }
            }

            return true;
        }
Beispiel #4
0
        public bool Process(string name, Record[] records)
        {
            RecordsRecord rr;
            if (!rdict.TryGetValue(name, out rr))
            {
                rr = new RecordsRecord {name = name, desc = name};
                rdict.Add(name, rr);
            }

            foreach (var r in records)
            {
                UpdateProgress();
                if (!CreateSubrecords(rr, r))
                {
                    return false;
                }
            }

            // now that we have subrecords, go back through all records
            foreach (var sr in rr.Items.OfType<Subrecord>())
            {
                // list of all subrecords matching the given name
                var ss = (from r in records from s in r.SubRecords where s.Name == sr.name select s).ToArray();

                ProcessSubRecord(sr, ss);
            }

            // Post Process
            var srs = rr.Subrecords;
            var itr = srs.GetEnumerator();
            for (bool atEnd = itr.MoveNext(); !atEnd;)
            {
                var sr = itr.Current;
                if (sr.repeat > 1)
                {
                    if (sr.size < 0)
                    {
                        sr.size = 0;
                        continue;
                    }

                    int count = sr.repeat;
                    for (int j = 1; j < count; ++j)
                    {
                        atEnd = itr.MoveNext();
                        if (atEnd)
                        {
                            sr = itr.Current;
                            if (sr.repeat == count)
                            {
                                sr.repeat = sr.optional = 0;
                            }
                            else
                            {
                                // Should be a group??
                            }
                        }
                        else
                        {
                            sr.repeat = sr.optional = 1;
                        }
                    }
                }
                else
                {
                    atEnd = itr.MoveNext();
                }
            }

            // sub records have been updated
            long minSize = records.Min(a => a.Size);
            long maxSize = records.Max(a => a.Size);
            if (maxSize == minSize)
            {
                // Uniform record size
            }
            else
            {
            }

            return true;
        }