コード例 #1
0
        private static Formplot?ReadFormplot(Stream metadataStream, Stream?pointDataStream, Version version, FormplotTypes[]?acceptedTypes)
        {
            using var reader = XmlReader.Create(metadataStream, CreateXmlReaderSettings());

            reader.MoveToElement();
            while (reader.Read() && reader.NodeType != XmlNodeType.EndElement)
            {
                if (reader.Name != FormplotRootTag && reader.Name != PropertiesRootTag)
                {
                    continue;
                }

                if (!EnumParser <FormplotTypes> .TryParse(reader.GetAttribute("Type") ?? "", out var plotType))
                {
                    plotType = FormplotTypes.None;                     // This code path is for Property Files (they don't have a form plot type)
                }
                if (acceptedTypes != null && !acceptedTypes.Contains(plotType))
                {
                    return(null);
                }

                var targetVersion = FormplotHelper.GetFileFormatVersion(plotType);
                if (version > targetVersion)
                {
                    throw new NotSupportedException($"Invalid form plot file. Version {version} is not supported.");
                }

                return(CreateFormplot(pointDataStream, version, plotType, reader));
            }

            return(null);
        }
コード例 #2
0
        private static void WriteFileVersion <TPoint, TGeometry>(Formplot <TPoint, TGeometry> plot, ZipArchive zipOutput) where TPoint : Point <TPoint, TGeometry>, new() where TGeometry : Geometry, new()
        {
            var versionInfoEntry = zipOutput.CreateEntry("fileversion.txt", CompressionLevel.NoCompression);

            versionInfoEntry.LastWriteTime = new DateTime(1980, 1, 1);

            using var versionInfoEntryStream = versionInfoEntry.Open();
            using var textWriter             = new StreamWriter(versionInfoEntryStream, Encoding.UTF8);

            textWriter.Write(FormplotHelper.GetFileFormatVersion(plot.FormplotType).ToString(2));
        }