Exemplo n.º 1
0
        public void Import(StreamReader reader)
        {
            Entries.Clear();
            while (!reader.EndOfStream)
            {
                try {
                    string str = reader.ReadLine();
                    if (str.Trim() != "")
                    {
                        string[] strArray = str.Split(TABS, StringSplitOptions.None);
                        if (strArray.Length != 3)
                        {
                            continue;
                        }
                        List <string> imported = new List <string>(3);

                        for (int i = 0; i < 3; i++)
                        {
                            string str3 = CsvUtil.Unformat(strArray [i]);
                            imported.Add(str3);
                        }
                        Entries.Add(new LocEntry(imported[0], imported[1], Boolean.Parse(imported[2])));
                    }
                } catch {}
            }
        }
Exemplo n.º 2
0
 public void Export(StreamWriter writer)
 {
     for (int j = 0; j < NumEntries; j++)
     {
         LocEntry entry = Entries[j];
         string   str   = CsvUtil.Format(entry[0]);
         for (int i = 1; i < 3; i++)
         {
             string current = entry[i];
             str += "\t" + CsvUtil.Format(current);
         }
         writer.WriteLine(str);
     }
 }
Exemplo n.º 3
0
        // read from given stream
        public DBFile Decode(StreamReader reader)
        {
            // another tool might have saved tabs and quotes around this
            // (at least open office does)
            string typeInfoName = reader.ReadLine().Replace("\t", "").Trim(QUOTES);

            string[] split = typeInfoName.Split(GUID_SEPARATOR, StringSplitOptions.RemoveEmptyEntries);
            if (split.Length == 2)
            {
                typeInfoName = split[0];
            }
            string versionStr = reader.ReadLine().Replace("\t", "").Trim(QUOTES);
            int    version;

            switch (versionStr)
            {
            case "1.0":
                version = 0;
                break;

            case "1.2":
                version = 1;
                break;

            default:
                version = int.Parse(versionStr);
                break;
            }

            DBFile file = null;

            // skip table header
            reader.ReadLine();
            List <String> read = new List <String>();

            while (!reader.EndOfStream)
            {
                read.Add(reader.ReadLine());
            }

            List <TypeInfo> infos = DBTypeMap.Instance.GetVersionedInfos(typeInfoName, version);

            foreach (TypeInfo info in infos)
            {
                bool parseSuccessful = true;

                List <DBRow> entries = new List <DBRow> ();
                foreach (String line in read)
                {
                    try {
                        String[] strArray = line.Split(TABS, StringSplitOptions.None);
                        if (strArray.Length != info.Fields.Count)
                        {
                            parseSuccessful = false;
                            break;
                        }
                        List <FieldInstance> item = new List <FieldInstance> ();
                        for (int i = 0; i < strArray.Length; i++)
                        {
                            FieldInstance field      = info.Fields [i].CreateInstance();
                            string        fieldValue = CsvUtil.Unformat(strArray [i]);
                            field.Value = fieldValue;
                            item.Add(field);
                        }
                        entries.Add(new DBRow(info, item));
#if DEBUG
                    } catch (Exception x) {
                        Console.WriteLine(x);
#else
                    } catch {
#endif
                        parseSuccessful = false;
                        break;
                    }
                }
                if (parseSuccessful)
                {
                    String       guid   = "";
                    DBFileHeader header = new DBFileHeader(guid, version, (uint)entries.Count, version != 0);
                    file = new DBFile(header, info);
                    file.Entries.AddRange(entries);
                    break;
                }
            }
            return(file);
        }