コード例 #1
0
ファイル: ODCCreator.cs プロジェクト: lunaxi7/XTMF
        public static void CreateOdc(string fileName, string xmlTemplate, string dataDirectory)
        {
            XmlSerializer deserializer = new XmlSerializer(typeof(CacheGenerationInfo));

            TextReader textReader = new StreamReader(xmlTemplate);

            CacheGenerationInfo info = (CacheGenerationInfo)deserializer.Deserialize(textReader);

            textReader.Close();

            OdcCreator odcCreator = new OdcCreator(info.HighestZone, info.Types, info.Times, info.Gap);

            foreach (var dimensionInfo in info.CacheInfo)
            {
                string fname = Path.Combine(dataDirectory, dimensionInfo.FileName);

                if (dimensionInfo.Is311)
                {
                    odcCreator.LoadEmme2(fname, dimensionInfo.TimeIndex, dimensionInfo.TypeIndex);
                }
                else
                {
                    if (dimensionInfo.SaveInTimes)
                    {
                        odcCreator.LoadCsvTimes(fname, dimensionInfo.Header, dimensionInfo.TimeIndex, dimensionInfo.TypeIndex);
                    }
                    else
                    {
                        odcCreator.LoadCsvTypes(fname, dimensionInfo.Header, dimensionInfo.TimeIndex, dimensionInfo.TypeIndex);
                    }
                }
            }
            odcCreator.Save(fileName, false);
        }
コード例 #2
0
        public void ReGenerate(string dataDirectory, string outputDirectory)
        {
            string fileName = Path.GetFileNameWithoutExtension(FileName);

            string path = Path.GetDirectoryName(FileName);

            if (path == null)
            {
                throw new IOException($"Unable to find the Directory name of {FileName}!");
            }
            string xmlFile = Path.Combine(path, fileName + ".xml");

            XmlSerializer deserializer = new XmlSerializer(typeof(CacheGenerationInfo));

            TextReader textReader = new StreamReader(xmlFile);

            CacheGenerationInfo info = (CacheGenerationInfo)deserializer.Deserialize(textReader);

            textReader.Close();

            OdcCreator odcCreator = new OdcCreator(HighestZone, Types, Times, Indexes.Length);

            foreach (var dimensionInfo in info.CacheInfo)
            {
                string fname = Path.Combine(dataDirectory, dimensionInfo.FileName);

                if (dimensionInfo.Is311)
                {
                    odcCreator.LoadEmme2(fname, dimensionInfo.TimeIndex, dimensionInfo.TypeIndex);
                }
                else
                {
                    if (dimensionInfo.SaveInTimes)
                    {
                        odcCreator.LoadCsvTimes(fname, dimensionInfo.Header, dimensionInfo.TimeIndex, dimensionInfo.TypeIndex);
                    }
                    else
                    {
                        odcCreator.LoadCsvTypes(fname, dimensionInfo.Header, dimensionInfo.TimeIndex, dimensionInfo.TypeIndex);
                    }
                }
            }
            var localFileName = Path.GetFileName(FileName);

            if (localFileName == null)
            {
                throw new IOException($"Unable to get the file name of {FileName}!");
            }
            odcCreator.Save(Path.Combine(outputDirectory, localFileName), true);
        }